tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Blevins <david.blev...@visi.com>
Subject Re: Fetching a Persistence Context
Date Fri, 16 Oct 2009 23:13:52 GMT

On Oct 16, 2009, at 12:36 PM, Jean-Louis MONTEIRO wrote:

> Sorry for that. It's an overall need that's why i pointed your post.

No worries.

> It seems to me the correct link is
> http://openejb.apache.org/3.0/persistence-context.html
> http://openejb.apache.org/3.0/persistence-context.html
>
> Anyway, shouldn't be possible to add the module name (or the jar name)
> instead of an hash.
> I should be more predictable for end users.
>
> I mean something like myModule.jar#myPU

Tried to go for that (and related), but the thing that kills it is  
that in most testing scenarios the module names are exactly the same.   
In maven all the module names end up being "classes" or "test- 
classes".  Similar for Eclipse, Intellij and Netbeans.  Seems in a  
build environment the classes are almost always output to a directory  
of a standard name.

I'm hoping the global JNDI functionality in Java EE 6 might open up  
some doors here.  It would still be something that the user has to  
configure for themselves, but there will at least be a way to bind all  
your persistence units to the new java:app/ or java:module/ namespaces  
so they can be looked up by fellow components in that app or module.

We could have a feature to do that automatically (perhaps with more  
JNDI name formatting magic), thought it won't necessarily be  
portable.  If they go to another container that doesn't have the  
feature they would still have to declare <persistence-context-ref>  
elements (or via annotation) in the app or module namespaces.

-David


> David Blevins wrote:
>>
>>
>> On Oct 15, 2009, at 8:33 AM, Jean-Louis MONTEIRO 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
>>
>> Wish I could delete that thread from the archive -- I should never
>> have given out those internal details.  It's not portable and it is
>> not even guaranteed to work in OpenEJB in the future.  That whole
>> hashcode thing is a really ugly workaround and I'd really like to  
>> find
>> another way to do that chunk of code.
>>
>> The @PersistenceContext can be used to make things available in JNDI
>> for lookup and is what should be used -- that or a <persistence-
>> context-ref> entry in xml.
>>
>> I'm not sure why this page is formatted so strangely, but it has the
>> right info:
>>
>>   http://openejb.apache.org/3.0/persistence-context-ref.html
>>
>> This is the wiki version which looks better:
>>
>>
>> http://cwiki.apache.org/confluence/display/OPENEJBx30/persistence-context
>>
>>
>> -David
>>
>>> 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.
>>>
>>>
>>
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/Fetching-a-Persistence-Context-tp25910491p25931122.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
>


Mime
View raw message