I'm not sure if I understand the overall goal.
Is this a case where the code that intends to use the
PeristenceContext (EntityManager) does not know the name of the
persistence unit and therefore cannot look it up or have it injected?
If so, it still should be possible to create a component that has an
@PersistenceContext reference to the unit and then can pass it
directly or indirectly to this more generic "work with any
EntityManager" code. Perhaps with a Singleton pattern like this one http://bit.ly/vklEb
You could also do a more generic version like this: http://bit.ly/10AsNt
Hope that helps!
-David
On Oct 15, 2009, at 4:03 PM, Quintin Beukes wrote:
Basically I need a way to progammatically retrieve a unit manager.
Information regarding the PU is supplied to a module manager in an
core module which has no knowledge of the module until it's notified
of it.
So, from your last e-mail, I assume it would then be possible to
annotate the persistence context in the Startup singleton of the
module, and then specify the class and field name to the module
manager, which would then use this information to construct a lookup
backwards, and then have it wrapped in a transaction (since the call
to the module manager is a business method invocation) - unless I
misunderstood the code.
Though... 10 seconds ago I also thought of an option of doing a JNDI
lookup of the Singleton itself and then invoke on this reference -
this should wrap it in a transaction, which I can then use to pass in
an injected EntityManager reference?
Quintin Beukes
On Fri, Oct 16, 2009 at 12:29 AM, Quintin Beukes <[email protected]
> wrote:
OK. So just to confirm that things are still the same.
I know that unit names need not be unique, so I assume you still
generate the unique ID suffix. How does OpenEJB then decide what to
do
with it. I tried looking around the code, but am a bit lost on where
it injects these entity managers and how it decides which persistence
unit to use. Could you perhaps tell me where to find this?
Quintin Beukes
On Thu, Oct 15, 2009 at 5:33 PM, Jean-Louis MONTEIRO
<[email protected]> wrote:
Hi Quintin,
you can use JNDI to get a reference.
Have a look here
http://www.nabble.com/Lookup-EntityManager-from-Stateless-EJB-Session-Bean-td24708299.html#a24737449
http://www.nabble.com/Lookup-EntityManager-from-Stateless-EJB-Session-Bean-td24708299.html#a24737449
Hope it helps.
Jean-Louis
Q Beukes wrote:
Hey,
When I have an EntityManager injected while having multiple
persistence units, I do it by specifying the unit name, something
like:
@PersistenceContext(unitName="Some-PU")
private EntityManager em;
Is it possible to do this not by injection, but fetching it by name
through an API of some sort?
Quintin Beukes
--
View this message in context:
http://www.nabble.com/Fetching-a-Persistence-Context-tp25910491p25910759.html
Sent from the OpenEJB User mailing list archive at Nabble.com.