Tuesday August 18, 2009
LOTD #22: How to inject JPA resources ? - PersistenceUnit vs PersistenceContext
Java Persistence API defines a standard object/relational mapping using
POJOs. In JPA, a persistence
unit is described using "persistence.xml", bundled with
the web application, injected into your web application and then POJOs
are used to access all the information from the underlying persistence
mechanism such as a database.
JPA can injected into your application couple of different ways as
shown below:
| @PersistenceUnit EntityManagerFactory emf; |
| @PersistenceContext EntityManager manager; |
Posted by Arun Gupta in General | Comments[1]
|
|
|
|
|
Today's Page Hits: 900
Total # blog entries: 1002
| « December 2009 | ||||||
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | ||
| Today | ||||||
Arun,
Maybe a tip for a follow-up TOTD: how to combine OSGi and JPA in GlassFish v3?
Example:
Bundle A is a WAB with a PU and a class Foo, Bundle B contains class Bar extends Foo. How can B persist instances of Bar using JPA? (the PU in Bundle A doesn't know how to persist class BAR).
I can come up with a number of solutions that all have drawbacks.
- Johan
Posted by Johan Vos on August 18, 2009 at 05:19 AM PDT #