It's not a secret anymore!*
The moose likes EJB and other Java EE Technologies and the fly likes Newbie to EJB, need help! 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 "Newbie to EJB, need help!" Watch "Newbie to EJB, need help!" New topic
Author

Newbie to EJB, need help!

Alan Smith
Ranch Hand

Joined: Oct 19, 2011
Posts: 152

Hi,

I am new to EJB technology. I am learning JSF and am using JPA to persist to my database. I just found out that you can also persist entities using EJB as well so I went and looked into EJB. My problem is that every description of what EJB is or does is so vast that I am having trouble pinpointing its correct/exact uses. For example, an example on wikipedia has EJB doing the same thing as JPA only that the method shown "is transactional and thread-safe by default". Usually in JPA you have to begin and commit your transaction. Does this make EJB the better option? Also, is it the @stateless annotation that declares the method threadsafe and transactional?

If someone could give me a good explanation of EJB "in laymans terms" so to speak, it would be much appreciated. At the minute I am a bit overwhelmed with the amount of information about it!

Thanks,
Alan
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1076
    
  10

Hi Alan,
EJB is of 3 types: Session, Enterprise and Message-Driven.
When the first version came out, you had all 3 types - where session beans would have business logic and entity beans will have persistence code. You can also use CMP (Container Managed Persistence) for Entity Beans in which case, you don't have to write the actual insert statements (the container will take care of handling persistence).

Since EJB 3.0, Entity Beans are not used or rather not called Entity Beans, but rather called JPA Entities. It is using JPA in an enterprise environment (note that you can use JPA in standalone apps too). So, technically JPA entities are the new form of Entity Beans.

The stateful and stateless stuff apply only for Session beans. Like I pointed out earlier, Session beans contain business logic which could include persisting data as well as sending a message to a queue etc.
The methods in a session bean themselves support distributed transactions (JTA) - so, if you do persistence with JPA that will be automatically included in a transaction.
Also, invocation of session bean methods can be subjected to declarative security restrictions - that is what the statement about Transactions/Security indicate.

I suggest you start with the EJB page of the tutorial (latest version).


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Alan Smith
Ranch Hand

Joined: Oct 19, 2011
Posts: 152

Ok, I will have a read of that, thanks.

Alan
 
jQuery in Action, 2nd edition
 
subject: Newbie to EJB, need help!
 
Similar Threads
Data Not inserting into Database JPA+Hibernate
Batch fetching using JPA
Using EJB3 in combination with Spring.
Not able to persist data by using EntityManager.
Reentrant okay in BDOM?