You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Marrrck <mm...@gmail.com> on 2009/08/12 00:00:01 UTC

openejb.altdd.prefix not working for persistence.xml

I've started using openEJB in conjunction with hibernate and derby to run
unit tests from within Eclipse. I've been trying to use the
openejb.altdd.prefix property to specify an alternate persistence.xml file
with the derby db drivers and some additional paramters, but it doesn't seem
to be getting picked up.

I'm also using the @LocalClient annotation on my tests to inject the session
beans that I am testing. 

I've got multiple modules in my class path that are being scanned, and they
look something like this:

jpa/classes/com... // entity beans
jpa/classes/META-INF/persistence.xml // not the one I want to use for unit
tests
jpa/classes/META-INF/test.persistence.xml // this is the one I want to use

ejb/classes/com... // session bean classes
ejb/classes/META-INF/ejb-jar.xml

test/classes/com... //unit tests annotated with @LocalClient
test/classes/META-INF/application-client.xml // this file just has the root
node so that openejb will scan this directory for @LocalClient

All my unit tests have this method:

@Before
  public void initializeInjection() throws NamingException {
    Properties p = new Properties();
    p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
    p.setProperty("openejb.altdd.prefix", "test");
    InitialContext initialContext = new InitialContext(p);
    initialContext = new InitialContext(p);
    initialContext.bind("inject", this);
  }

When I step through the unit tests, I get to the initialContext = new
InitialContext(p) line and it seems to load persistence.xml and not
test.persistence.xml. I can tell this because of this line in the log:

INFO: Using dialect: org.hibernate.dialect.Oracle10gDialect
and because all my tests fail saying that the tables do not exist (since
test.persistence.xml has <property name="hibernate.hbm2ddl.auto"
value="create-drop" /> but persistence.xml does not).

If I remove persistence.xml and just keep test.persistence.xml, I get errors
like this complaining about the ejb/classes and the test/classes:

ERROR - FAIL ... UserFinderFacade:	A persistence unit must be defined via
META-INF/persistence.xml to satisfy @PersistenceContext ref "em" to unit
"PromoPersistence".  An example of a suitable persistence.xml might
be:<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="1.0"><persistence-unit
name="PromoPersistence"><jta-data-source>java:openejb/Resource/myDataSource</jta-data-source><non-jta-data-source>java:openejb/Resource/myUnmanagedDataSource</non-jta-data-source><properties><property
name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)"/></properties></persistence-unit></persistence>
ERROR - Invalid
EjbModule(path=C:\workfolder\promo.service\build\ejb\classes)

If I copy test.persistence.xml into all 3 META-INF directories, then it
picks up the test.persistence.xml in the other folders and puts this in the
logs:

INFO - AltDD persistence.xml ->
file:/C:/workfolder/myproj/build/ejb/classes/META-INF/test.persistence.xml
INFO - AltDD persistence.xml ->
file:/C:/workfolder/myproj/build/ejb/classes/META-INF/test.persistence.xml
INFO - Beginning load: C:\workfolder\myproj\build\test\classes
INFO - AltDD persistence.xml ->
file:/C:/workfolder/myproj/build/test/classes/META-INF/test.persistence.xml
INFO - Beginning load: C:\workfolder\promo.service\build\jpa\classes

but not the one in the jpa directory, and I still get the "A persistence
unit must be defined via META-INF/persistence.xml"  for the ejb and test
jars. 

If I throw a test.ejb-jar.xml into classes/jpa/META-INF then my
test.persistence.xml does get picked up, and I see this in the logs:
INFO - AltDD persistence.xml ->
file:/C:/workfolder/promo.service/build/jpa/classes/META-INF/test.persistence.xml
INFO - AltDD ejb-jar.xml ->
file:/C:/workfolder/promo.service/build/jpa/classes/META-INF/test.ejb-jar.xml
INFO - AltDD persistence.xml ->
file:/C:/workfolder/promo.service/build/jpa/classes/META-INF/test.persistence.xml
INFO - AltDD ejb-jar.xml ->
file:/C:/workfolder/promo.service/build/jpa/classes/META-INF/test.ejb-jar.xml

But I still get the same error. If I just remove all those test.* files and
make my persistence.xml valid for my test setup, then everything runs
without error.


Any ideas? I would really like to use this openejb.altdd.prefix to specify
different persistence units if I could.

Please let me know if you need any more information. I could probably make a
simple test case to reproduce this if required as well....

-- 
View this message in context: http://www.nabble.com/openejb.altdd.prefix-not-working-for-persistence.xml-tp24926543p24926543.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: openejb.altdd.prefix not working for persistence.xml

Posted by Jean-Louis MONTEIRO <je...@atosorigin.com>.
Hi again,

i checked with David and it should work with persistence.xml too.
I created a jira https://issues.apache.org/jira/browse/OPENEJB-1059 and i
will try to solve it ASAP.

Thanks for pointing that.

Jean-Louis



Jean-Louis MONTEIRO wrote:
> 
> Hello,
> 
> may be David can give more inputs.
> But AFAIK it only works with ejb-jar.xml, env-entries.properties.
> 
> Jean-Louis
> 
> 
> 
> Marrrck wrote:
>> 
>> I've started using openEJB in conjunction with hibernate and derby to run
>> unit tests from within Eclipse. I've been trying to use the
>> openejb.altdd.prefix property to specify an alternate persistence.xml
>> file with the derby db drivers and some additional paramters, but it
>> doesn't seem to be getting picked up.
>> 
>> I'm also using the @LocalClient annotation on my tests to inject the
>> session beans that I am testing. 
>> 
>> I've got multiple modules in my class path that are being scanned, and
>> they look something like this:
>> 
>> jpa/classes/com... // entity beans
>> jpa/classes/META-INF/persistence.xml // not the one I want to use for
>> unit tests
>> jpa/classes/META-INF/test.persistence.xml // this is the one I want to
>> use
>> 
>> ejb/classes/com... // session bean classes
>> ejb/classes/META-INF/ejb-jar.xml
>> 
>> test/classes/com... //unit tests annotated with @LocalClient
>> test/classes/META-INF/application-client.xml // this file just has the
>> root node so that openejb will scan this directory for @LocalClient
>> 
>> All my unit tests have this method:
>> 
>> @Before
>>   public void initializeInjection() throws NamingException {
>>     Properties p = new Properties();
>>     p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
>> "org.apache.openejb.client.LocalInitialContextFactory");
>>     p.setProperty("openejb.altdd.prefix", "test");
>>     InitialContext initialContext = new InitialContext(p);
>>     initialContext = new InitialContext(p);
>>     initialContext.bind("inject", this);
>>   }
>> 
>> When I step through the unit tests, I get to the initialContext = new
>> InitialContext(p) line and it seems to load persistence.xml and not
>> test.persistence.xml. I can tell this because of this line in the log:
>> 
>> INFO: Using dialect: org.hibernate.dialect.Oracle10gDialect
>> and because all my tests fail saying that the tables do not exist (since
>> test.persistence.xml has <property name="hibernate.hbm2ddl.auto"
>> value="create-drop" /> but persistence.xml does not).
>> 
>> If I remove persistence.xml and just keep test.persistence.xml, I get
>> errors like this complaining about the ejb/classes and the test/classes:
>> 
>> ERROR - FAIL ... UserFinderFacade:	A persistence unit must be defined via
>> META-INF/persistence.xml to satisfy @PersistenceContext ref "em" to unit
>> "PromoPersistence".  An example of a suitable persistence.xml might
>> be:<persistence xmlns="http://java.sun.com/xml/ns/persistence"
>> version="1.0"><persistence-unit
>> name="PromoPersistence"><jta-data-source>java:openejb/Resource/myDataSource</jta-data-source><non-jta-data-source>java:openejb/Resource/myUnmanagedDataSource</non-jta-data-source><properties><property
>> name="openjpa.jdbc.SynchronizeMappings"
>> value="buildSchema(ForeignKeys=true)"/></properties></persistence-unit></persistence>
>> ERROR - Invalid
>> EjbModule(path=C:\workfolder\promo.service\build\ejb\classes)
>> 
>> If I copy test.persistence.xml into all 3 META-INF directories, then it
>> picks up the test.persistence.xml in the other folders and puts this in
>> the logs:
>> 
>> INFO - AltDD persistence.xml ->
>> file:/C:/workfolder/myproj/build/ejb/classes/META-INF/test.persistence.xml
>> INFO - AltDD persistence.xml ->
>> file:/C:/workfolder/myproj/build/ejb/classes/META-INF/test.persistence.xml
>> INFO - Beginning load: C:\workfolder\myproj\build\test\classes
>> INFO - AltDD persistence.xml ->
>> file:/C:/workfolder/myproj/build/test/classes/META-INF/test.persistence.xml
>> INFO - Beginning load: C:\workfolder\promo.service\build\jpa\classes
>> 
>> but not the one in the jpa directory, and I still get the "A persistence
>> unit must be defined via META-INF/persistence.xml"  for the ejb and test
>> jars. 
>> 
>> If I throw a test.ejb-jar.xml into classes/jpa/META-INF then my
>> test.persistence.xml does get picked up, and I see this in the logs:
>> INFO - AltDD persistence.xml ->
>> file:/C:/workfolder/promo.service/build/jpa/classes/META-INF/test.persistence.xml
>> INFO - AltDD ejb-jar.xml ->
>> file:/C:/workfolder/promo.service/build/jpa/classes/META-INF/test.ejb-jar.xml
>> INFO - AltDD persistence.xml ->
>> file:/C:/workfolder/promo.service/build/jpa/classes/META-INF/test.persistence.xml
>> INFO - AltDD ejb-jar.xml ->
>> file:/C:/workfolder/promo.service/build/jpa/classes/META-INF/test.ejb-jar.xml
>> 
>> But I still get the same error. If I just remove all those test.* files
>> and make my persistence.xml valid for my test setup, then everything runs
>> without error.
>> 
>> 
>> Any ideas? I would really like to use this openejb.altdd.prefix to
>> specify different persistence units if I could.
>> 
>> Please let me know if you need any more information. I could probably
>> make a simple test case to reproduce this if required as well....
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/openejb.altdd.prefix-not-working-for-persistence.xml-tp24926543p24943429.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: openejb.altdd.prefix not working for persistence.xml

Posted by Jean-Louis MONTEIRO <je...@atosorigin.com>.
Hello,

may be David can give more inputs.
But AFAIK it only works with ejb-jar.xml, env-entries.properties.

Jean-Louis



Marrrck wrote:
> 
> I've started using openEJB in conjunction with hibernate and derby to run
> unit tests from within Eclipse. I've been trying to use the
> openejb.altdd.prefix property to specify an alternate persistence.xml file
> with the derby db drivers and some additional paramters, but it doesn't
> seem to be getting picked up.
> 
> I'm also using the @LocalClient annotation on my tests to inject the
> session beans that I am testing. 
> 
> I've got multiple modules in my class path that are being scanned, and
> they look something like this:
> 
> jpa/classes/com... // entity beans
> jpa/classes/META-INF/persistence.xml // not the one I want to use for unit
> tests
> jpa/classes/META-INF/test.persistence.xml // this is the one I want to use
> 
> ejb/classes/com... // session bean classes
> ejb/classes/META-INF/ejb-jar.xml
> 
> test/classes/com... //unit tests annotated with @LocalClient
> test/classes/META-INF/application-client.xml // this file just has the
> root node so that openejb will scan this directory for @LocalClient
> 
> All my unit tests have this method:
> 
> @Before
>   public void initializeInjection() throws NamingException {
>     Properties p = new Properties();
>     p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.openejb.client.LocalInitialContextFactory");
>     p.setProperty("openejb.altdd.prefix", "test");
>     InitialContext initialContext = new InitialContext(p);
>     initialContext = new InitialContext(p);
>     initialContext.bind("inject", this);
>   }
> 
> When I step through the unit tests, I get to the initialContext = new
> InitialContext(p) line and it seems to load persistence.xml and not
> test.persistence.xml. I can tell this because of this line in the log:
> 
> INFO: Using dialect: org.hibernate.dialect.Oracle10gDialect
> and because all my tests fail saying that the tables do not exist (since
> test.persistence.xml has <property name="hibernate.hbm2ddl.auto"
> value="create-drop" /> but persistence.xml does not).
> 
> If I remove persistence.xml and just keep test.persistence.xml, I get
> errors like this complaining about the ejb/classes and the test/classes:
> 
> ERROR - FAIL ... UserFinderFacade:	A persistence unit must be defined via
> META-INF/persistence.xml to satisfy @PersistenceContext ref "em" to unit
> "PromoPersistence".  An example of a suitable persistence.xml might
> be:<persistence xmlns="http://java.sun.com/xml/ns/persistence"
> version="1.0"><persistence-unit
> name="PromoPersistence"><jta-data-source>java:openejb/Resource/myDataSource</jta-data-source><non-jta-data-source>java:openejb/Resource/myUnmanagedDataSource</non-jta-data-source><properties><property
> name="openjpa.jdbc.SynchronizeMappings"
> value="buildSchema(ForeignKeys=true)"/></properties></persistence-unit></persistence>
> ERROR - Invalid
> EjbModule(path=C:\workfolder\promo.service\build\ejb\classes)
> 
> If I copy test.persistence.xml into all 3 META-INF directories, then it
> picks up the test.persistence.xml in the other folders and puts this in
> the logs:
> 
> INFO - AltDD persistence.xml ->
> file:/C:/workfolder/myproj/build/ejb/classes/META-INF/test.persistence.xml
> INFO - AltDD persistence.xml ->
> file:/C:/workfolder/myproj/build/ejb/classes/META-INF/test.persistence.xml
> INFO - Beginning load: C:\workfolder\myproj\build\test\classes
> INFO - AltDD persistence.xml ->
> file:/C:/workfolder/myproj/build/test/classes/META-INF/test.persistence.xml
> INFO - Beginning load: C:\workfolder\promo.service\build\jpa\classes
> 
> but not the one in the jpa directory, and I still get the "A persistence
> unit must be defined via META-INF/persistence.xml"  for the ejb and test
> jars. 
> 
> If I throw a test.ejb-jar.xml into classes/jpa/META-INF then my
> test.persistence.xml does get picked up, and I see this in the logs:
> INFO - AltDD persistence.xml ->
> file:/C:/workfolder/promo.service/build/jpa/classes/META-INF/test.persistence.xml
> INFO - AltDD ejb-jar.xml ->
> file:/C:/workfolder/promo.service/build/jpa/classes/META-INF/test.ejb-jar.xml
> INFO - AltDD persistence.xml ->
> file:/C:/workfolder/promo.service/build/jpa/classes/META-INF/test.persistence.xml
> INFO - AltDD ejb-jar.xml ->
> file:/C:/workfolder/promo.service/build/jpa/classes/META-INF/test.ejb-jar.xml
> 
> But I still get the same error. If I just remove all those test.* files
> and make my persistence.xml valid for my test setup, then everything runs
> without error.
> 
> 
> Any ideas? I would really like to use this openejb.altdd.prefix to specify
> different persistence units if I could.
> 
> Please let me know if you need any more information. I could probably make
> a simple test case to reproduce this if required as well....
> 
> 

-- 
View this message in context: http://www.nabble.com/openejb.altdd.prefix-not-working-for-persistence.xml-tp24926543p24935056.html
Sent from the OpenEJB User mailing list archive at Nabble.com.