I have an entity which contains a number of primitively typed attributes which I would obviously like to persist through CMP, however it also contains an attribute which is/will become a network of smaller java objects. For the moment I can store this attirbute as a BLOB (byte array via CMP) but later in the project lifetime I am going to have to build a database structure to store these objects in a more relational manner (for reporting purposes). I would like the entity bean to control the existence of these (dependent) java objects but am concerned about transactional integrity. If I use jdbc picking up a connection from the same DataSource as is used for the CMP will the persistence of the java objects over this connection be automatically part of the transaction that I used to access my entity bean to make the accessor/mutator calls or will I have to do something extra to ensure it is included in the transaction ? Also although currently I will be doing the persistence during the ejbStore and ejbLoad methods I was intending to lazy load the java objects when required. In many cases they won't be required so it seems wasteful to tie them in to every access of the entity. (If I do need to do something extra is this a weblogic fix or is it portable across EJB servers, nb currently using Weblogic 5.1 ) [This message has been edited by Tim Crampin (edited October 12, 2000).] [This message has been edited by Tim Crampin (edited October 12, 2000).]
If you're worried about your transactions, would you consider using BMP? You can specifically decide the demarcation of your transactions by placing the critical code between javax.transaction.UserTransaction.begin and javax.transaction.UserTransaction.commit method calls. For CMP, if you set the Transaction property to 'Required' (aka TX_REQUIRED) the bean will always run in a transaction, which has the duration of the method - ie the container begins the transaction at the method start and issues a commit or rollback at the method end. So if you make sure that your critical operations are happening in the same method, you'll be ok. You've probably already seen them, but there is a good chapter in the Ed Roman EJB book on transactions (ch.10) and the EJB 1.1 spec (ch.11) goes into a fair bit of detail too. I believe that this is a standard feature of WLS as it implements the EJB 1.1 spec. However, there is a certain amount of flexibility in how a vendor implements the spec. In principle, it should be portable across EJB servers.
The first person to drink cow's milk. That started off as a dare from this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop