File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes EJB 2.1 question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB 2.1 question" Watch "EJB 2.1 question" New topic

EJB 2.1 question

Varun Chopra
Ranch Hand

Joined: Jul 10, 2008
Posts: 211
I have to write code for following:

* 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.


-Varun -
(My Blog) - Online Certifications - Webner Solutions
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
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 ]
I agree. Here's the link:
subject: EJB 2.1 question
It's not a secret anymore!