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 now  without EJB 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 "now  without EJB" Watch "now  without EJB" New topic

now without EJB

prasanna pati
Ranch Hand

Joined: Jan 29, 2005
Posts: 46
in my project I have used EJB ( CMP ) ,, now my manager wants to 'remove ' the EJB part for 1-2 module of the project OK ? now that means from java program I have to access a DAO and from a DAO I will access the database . is this approach ok ? I know core java and part of EJB which I have worked on . not much

so please help .
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Or you could rewire your exiting beans to use something like Hibernate. You will need to rethink session/transaction handling, though. In the EJB world it's common to leave that to the container - without one, that's the responsibilty of your code.
Chintan Rajyaguru
Ranch Hand

Joined: Aug 19, 2001
Posts: 341
This kind of problems require some analysis but here is an oversimplified answer:
Look at your EJB CMP layer and think about the things it's doing. In most cases, CMP EJBs,
1. Capture the domain model as EJBs
2. Define mappings to map EJBs to the database tables
3. Container takes care of executing transactions etc.

If you want to move away from CMP EJBs you will have to think of ways to do these things in your code. Here is what I would propose:
1. Create a layer of domain layer POJOs. If you had say AccountEJB, you will now have AccountVO. Note that you can still have primary key class etc. like you did before
2. Create a way to map VOs to database tables. This can be done by either creating a layer of DAOs and writing JDBC code in them OR by using a framework such as Toplink or Hibernate
3. Create a layer of stateless session beans (you probably have this already), which would either access DAO or invoke Hibernate to perform CRUD operations. Define transactions etc. on sessions beans

To specifically, answer your question, yes, you can use Java code - DAO - database as long as you take care of transactions etc.

Hope this helps, let me know if you have more questions...

Chintan - Coming soon!
I agree. Here's the link:
subject: now without EJB
It's not a secret anymore!