• Post Reply Bookmark Topic Watch Topic
  • New Topic

Web Applications: EJB 3 Vs. Plain JPA  RSS feed

 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For persistence in a web application, what are the advantages of using EJB 3 as opposed to just incorporating the Java Persistence API (JPA) into the web application classes?
 
Debu Panda
author
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are few benefits you get from EJB.

1. Declarative transaction. Otherwise you have to manage your TXs

2. Dependency Injection of transaction scoped container-managed EntityManager.

3. Extended persistence context if you are using stateful applications


Read chapter 12 for details.
 
Reza Rahman
author
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Merrill:

Debu already covered the major cases for using session beans. In a highly message oriented environment, MDBs have obviuos uses. Some other issues to consider are basic AOP support through interceptors, a more clearly defined boundary for exposing the high level application API as web services, declarative security, and the like. Anothjer subtle issue people often forget is thread-safety.

Not all parts of the JPA API is thread-safe by default, whereas session beans are. If you are not careful, you can easily expose a non-thread safe JPA object into a non-thread safe context (such as the HTTP session).

Reza
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!