users@glassfish.java.net

Re: Same app twice using JPA

From: Edson Carlos Ericksson Richter <edson.richter_at_mgrinformatica.com.br>
Date: Wed, 20 Jun 2007 17:44:58 -0300

Please, see comments inline...


Marina Vatkina escreveu:
> In Glassfish each deployed app gets its own class loader, so each
> class loader loads its own provider class and as a result, each
> persistence.xml is processed completely separately.
good, but I'm still having same problem on Glassfish... Maybe I need a
more recent version (I'm using V1U1)
>
> Now, if your webserver (Tomcat or any other) has everything loaded by
> a single class loader, you have the same situation as you would in a
> Java SE environment,
> and only 1 PU with a specific name can exist.
I do believe this is the problem I'm facing...
>
> Now, that said, you do not need to change .java classes, only PU names
> in the persistence.xml (you already have different datasources or
> driver properties in those files, right?) to avoid the problem your
> are getting into.
But Java code need to know what PU to load in the code:

Persistence.createEntityManagerFactory("GeDoc2PU");

(maybe I did not understood your comment!)

Thanks,

Edson Richter

>
> Best regards,
> -marina
>
> Edson Carlos Ericksson Richter wrote:
>> I getting things clear.
>> Scenario is:
>>
>> I have one server, and need to deploy same application twice, but one
>> should not access database information from another.
>> So, when I "build" application on NetBeans, I have a custom ANT build
>> step that changes all .XML files to point to correct database - but I
>> would not change .java files (where PU is defined).
>>
>> About point 1 you highlited, I think is exactly problem I'm facing
>> (since I have two applications using a static PersistenceManager
>> it's being tied up to one classloader !?).
>> About point 2, my expectation is two applications having same PU name
>> access different databases (and have own cache - so they don't trows
>> ClassCastException when loading a Customer from Database).
>>
>> So, the point is: is possible to load PersistenceContext from JNDI in
>> either Tomcat and Glassfish, so I don't need two different pieces of
>> code for each server?
>>
>> Thanks for help!
>>
>> Edson Richter
>>
>>
>>
>> glassfish_at_javadesktop.org escreveu:
>>
>>> Whether TopLink will work in your scenario or not, will depend on 2
>>> things - your expectations and the class loader.
>>> 1. The class loader. In the same class loader, there can be only one
>>> PU with a particular name. I think there is an open issue to allow
>>> the same name but different overrides as specified in the map that
>>> you pass to Persistence.createEMF() call.
>>>
>>> 2. Expectations. Do you expect those two apps to share a PU or have
>>> their own copies? Depending on how Tomcat handles class loaders (GF
>>> uses a separate class loader for each application), you'll get a
>>> different answer to your original question.
>>>
>>> Regards,
>>> -marina
>>> [Message sent by forum member 'mvatkina' (mvatkina)]
>>>
>>> http://forums.java.net/jive/thread.jspa?messageID=223161
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>>
>>>
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>
>