-1

Is there any documentation / articles identifying best practices / rules for when should one use JPA in an ejb container vs. when is it appropriate to use JPA in a web container?

At a high level - couple of things that I can think about is if we have JPA in WAR then the transactional code will need to be managed by the developer in UserTransactions and it cannot be reused by other modules or even the EJB in the same application.

adbdkb
  • 1,897
  • 6
  • 37
  • 66
  • It is normally always best practice to use an EJB Container, because it is more a security feature to have your business logic on a different classpath than your web container. It is the standard JEE way. But at the end you have to decide. Please read the JavaEE documentation for more details. – Pintus Apr 02 '16 at 11:54
  • This question doesn't have a good answer, I'm afraid. What is best; bike or car? It depends. Having an EJB container available and still run JPA-code in the web-container is just plain weird. I doubt you will find many articles on the subject. Maybe for some semi-persistent storage in an in-memory database. – jon martin solaas Apr 03 '16 at 00:14

1 Answers1

0

I typically use JPA for either Java SE applications or in a Container. The SE application is really only playing around or doing database loads or setup. I have setup JPA in Tomcat, but I wasn't really pleased with the end result and felt there was some issues that couldn't really be resolved.

EDIT: That said, consider Spring/Hibernate runs in a servlet container under your HTTP server of choice, and seems to be a pretty popular and mature platform, but also quite vendor specific. It will do just about anything I can think of that a Java EE certified container will do and perhaps more.

I think your considerations come down to what kind of application you're building which, in turn, provides a lot of input about what database to use.

K.Nicholas
  • 10,956
  • 4
  • 46
  • 66
  • It is not that I want to do it. I need the comparison doc / article to convince it to someone else showing them pros and cons comparisons for both approaches. – adbdkb Apr 02 '16 at 02:09