[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openejb-user
Subject:    Re: PersistenceContext problems after upgrade to 3.1
From:       "Olivier THIERRY" <olivier.thierry () gmail ! com>
Date:       2008-11-12 13:57:19
Message-ID: 6bbf89b80811120557g7b82b0d8s4815d82cbe99cc1d () mail ! gmail ! com
[Download RAW message or body]


Thanks a lot for your help David, the new
"openejb.deployments.classpath.ear" property helped me to reproduce
behaviour I had with Open EJB 3.0. I will have a look later on what you say
about persistence.xml files in test-classes directory, this could be a good
idea !

Olivier

2008/11/10 David Blevins <david.blevins@visi.com>

> Hi Oliver,
>
> In OpenEJB 3.0, each module (ejb-jar) that we discovered in the classpath
> was treated as if it had been deployed individually as a standalone app.
>  This put the restriction in there that any persistence units you referenced
> had to be in the same app (ejb-jar module) and were not visible in other
> apps.
>
> In OpenEJB 3.1, each module (ejb-jar, persistence archive, or resource
> arcive) that we discover in the classpath will be treated by default as if
> it had been deployed together as an ear.  This allows for a more straight
> forward way of sharing persistence units across all modules.  So persistence
> units can be reused without the need to redeclare them. As well, they can be
> in a module all by itself, no ejbs or ejb-jar.xml required.
>
> To get OpenEJB 3.1 to act like OpenEJB 3.0 in this regard, set the new
> "openejb.deployments.classpath.ear" property to "false".  That will get
> everything working as it did in 3.0 and you can explore new options with a
> functioning build.
>
> With the new functionality some of those options would be to only declare
> the persistence.xml in either t4-core-utils or t4-core-commons and have it
> reused in both, or move it it to third module say t4-core-persistence and
> reuse it in both.  Seems the t4Seam unit in t4-core-commons and
> t4-core-utils aren't exactly the same, so not sure which would be the one
> you reuse and which you delete.
>
> Another clever approach might be to put the persistence.xml files in the
> maven test-classes/ directory where maven will ensure it's only visible when
> the tests for that module are run (using the <jar-file> element where
> needed).
>
> Hope this helps and hope you find the new options useful.
>
> -David
>
>
>
> On Nov 10, 2008, at 5:05 AM, chawax wrote:
>
>
>> Hi,
>>
>> I used OpenEJB 3.0 as embedded EJB3 container for unit tests in a Maven
>> project. Now I try to upgrade to OpenEJB 3.1 but I encounter problems I
>> had
>> not seen before. Actually for some development organization reasons, my
>> EJB3
>> entities are in many Maven projects, each one having its persistence.xml
>> file with the same persistence unit. There are dependencies between these
>> projects.
>>
>> For example I have two projects : t4-core-utils and t4-core-commons. The
>> second one depends on the first one. So in the persistence.xml for
>> t4-core-commons, I use jar-file tag.
>>
>> The persistence.xml file for t4-core-commons is like this :
>>
>> <persistence
>>   xmlns="http://java.sun.com/xml/ns/persistence"
>>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
>>
>> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
>>   version="1.0">
>>   <persistence-unit name="t4Seam">
>>       <provider>org.hibernate.ejb.HibernatePersistence</provider>
>>       <jta-data-source>java:/jdbc/t4Seam</jta-data-source>
>>       <jar-file>../test-classes/lib/t4-core-utils-core.jar</jar-file>
>>        <mapping-file>META-INF/orm-commons.xml</mapping-file>
>>        <mapping-file>META-INF/orm-utils.xml</mapping-file>
>>       <properties>
>>           <property name="hibernate.hbm2ddl.auto" value="update"/>
>>           <property name="hibernate.show_sql" value="false"/>
>>       </properties>
>>   </persistence-unit>
>> </persistence>
>>
>> And the persistence.xml file for t4-core-utils is like this :
>>
>> <persistence
>>   xmlns="http://java.sun.com/xml/ns/persistence"
>>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
>>
>> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
>>   version="1.0">
>>   <persistence-unit name="t4Seam">
>>       <provider>org.hibernate.ejb.HibernatePersistence</provider>
>>       <jta-data-source>java:/jdbc/t4Seam</jta-data-source>
>>        <mapping-file>META-INF/orm-utils.xml</mapping-file>
>>       <properties>
>>           <property name="hibernate.hbm2ddl.auto" value="update"/>
>>           <property name="hibernate.show_sql" value="false"/>
>>       </properties>
>>   </persistence-unit>
>> </persistence>
>>
>> But when my app starts, I have errors using @PersistenceContext annotation
>> in my EJB3 session beans.
>>
>> For example :
>> ERROR - FAIL ... EmployeeDaoImpl:       @PersistenceContext unitName has
>> multiple
>> matches: unitName "t4Seam" has 2 possible matches.
>>
>> What has changed about this from 3.0 to 3.1 ? And what should I do to make
>> it work as it used to work ?
>>
>> Thanks in advance,
>>
>> Olivier
>> --
>> View this message in context:
>> http://www.nabble.com/PersistenceContext-problems-after-upgrade-to-3.1-tp20419521p20419521.html
>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>
>>
>>
>


-- 
Seules 2 choses sont infinies : l'univers et la bêtise humaine ; et encore
pour l'univers, je ne suis pas sûr … (Einstein)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic