This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
* There are 2 databases DB1 and DB2, they have same schema * DB1 has some CAR objects, data of which needs to be transferred to DB2 via code * CAR objects have 2 types of information - METADATA (common for a group of cars - like attribute list (color, weight, price etc.) ) and DATA (different for each car - like attribute values (red, 600kg, $10000 etc.)). There are 6 tables in total - 2 for MetaData, 4 for Data. Transfer of all CAR objects must happen in a single transaction including MetaData and Data
I am thinking of following:
Also I am thinking of using CMT to put transferCARs() in a transaction, with Required attribute for transferMetaData() and transferData() to continue the same transaction.
My questions are:
1. Should I put transferCARs() in a stateless session bean and transferMetaData() & transferData() in a BMP? Or should I put all methods in statless session bean?
2. Do you see any flaw in above thoughts and is there a better alternative?
In future I may have to add more tables to transferData() especially when we would like to transfer photo information for each CAR as well.
The business operation of moving data can be coded in a stateless Session EJB. A method signature for this operation might be:
Container Managed Transaction attributes can then be applied to the method above.
The private methods that help implement the business operation are not exposed to client objects. Hence, there is no need to apply CMT attributes to these methods.
The code in the Session EJB should use a Data Access Object for database operations (if not using Entity EJB). Raw JDBC code or Hibernate code goes in the DAO implmentation class, not the Session EJB method. [ October 14, 2008: Message edited by: James Clark ]