OpenEJB - Missing required persistence.xml

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
28 messages Options
12
Reply | Threaded
Open this post in threaded view
|

OpenEJB - Missing required persistence.xml

Karsten.Ohme
Hi,

I'm experimenting for one day with OpenEJB 3.0-beta-2, but I'm stuck. I
have tried different approaches to test EJBs, ejb3unit, JBoss
embeddable, but OpenEJB seems to be the best, although it also does not
work for me.

I always get a

- FAIL ... PatternManagementDaoImpl: Missing required persistence.xml
for @PersistenceContext ref "em" to unit "pattern-managementPu"

What's wrong? It is there. And where should it be placed? In META-INF
like usually? It seems that it is later found.

What I want to do is to use an Apache Derby database (in memory) which
is automatically initilialized. What do I have to define and where, that
this works?

Can I define the order in which the EJB modules are loaded?

Thanks,
Karsten

Apache OpenEJB 3.0-beta-2    build: 20080131-03:38
http://openejb.apache.org/
- openejb.home = C:\workspace\pattern-management\pattern-management-impl
- openejb.base = C:\workspace\pattern-management\pattern-management-impl
- Configuring Service(id=Default Security Service, type=SecurityService,
provider-id=Default Security Service)
- Configuring Service(id=Default Transaction Manager,
type=TransactionManager, provider-id=Default Transaction Manager)
- Configuring Service(id=Derby Database, type=Resource,
provider-id=Default JDBC Database)
- Configuring Service(id=Default JDK 1.3 ProxyFactory,
type=ProxyFactory, provider-id=Default JDK 1.3 ProxyFactory)
- Configuring Service(id=Default Stateless Container, type=Container,
provider-id=Default Stateless Container)
- Found EjbModule in classpath:
C:\workspace\pattern-management\pattern-management-impl\src\main\resourc
es
- Found EjbModule in classpath:
C:\workspace\pattern-management\pattern-management-impl\src\test\resourc
es
- Configuring app:
C:\workspace\networkstorage-management\networkstorage-management-impl\ta
rget\classes
- Loaded Module:
C:\workspace\networkstorage-management\networkstorage-management-impl\ta
rget\classes
- Configuring app:
C:\workspace\pattern-management\pattern-management-impl\target\classes
- FAIL ... PatternManagementDaoImpl: Missing required persistence.xml
for @PersistenceContext ref "em" to unit "pattern-managementPu"
- FAIL ... TestFacadeImpl: Missing required persistence.xml for
@PersistenceContext ref "em" to unit "pattern-managementPu"
- Jar not loaded.
C:\workspace\pattern-management\pattern-management-impl\target\classes.
Module failed validation.
AppModule(path=C:\workspace\pattern-management\pattern-management-impl\t
arget\classes)
- Configuring app:
C:\workspace\pattern-management\pattern-management-impl\src\main\resourc
es
- Configuring PersistenceUnit(name=pattern-managementPu, provider=null)
- Loaded Module:
C:\workspace\pattern-management\pattern-management-impl\src\main\resourc
es
- Configuring app:
C:\workspace\pattern-management\pattern-management-impl\src\test\resourc
es
- Configuring PersistenceUnit(name=pattern-managementPu, provider=null)
- Loaded Module:
C:\workspace\pattern-management\pattern-management-impl\src\test\resourc
es
- Creating ProxyFactory(id=Default JDK 1.3 ProxyFactory)
- Creating TransactionManager(id=Default Transaction Manager)
- Creating SecurityService(id=Default Security Service)
- Creating Resource(id=Derby Database)
- Creating Container(id=Default Stateless Container)
- Assembling app:
C:\workspace\networkstorage-management\networkstorage-management-impl\ta
rget\classes
- Jndi(name=NetworkStorageServiceImplRemote) -->
Ejb(deployment-id=NetworkStorageServiceImpl)
- Created Ejb(deployment-id=NetworkStorageServiceImpl,
ejb-name=NetworkStorageServiceImpl, container=Default Stateless
Container)
- Deployed
Application(path=C:\workspace\networkstorage-management\networkstorage-m
anagement-impl\target\classes)
- Assembling app:
C:\workspace\pattern-management\pattern-management-impl\src\main\resourc
es
- PersistenceUnit(name=pattern-managementPu, provider=null)
- JAVA AGENT NOT INSTALLED. The JPA Persistence Provider requested
installation of a ClassFileTransformer which requires a JavaAgent.  See
http://openejb.apache.org/3.0/javaagent.html
- Deployed
Application(path=C:\workspace\pattern-management\pattern-management-impl
\src\main\resources)
- Assembling app:
C:\workspace\pattern-management\pattern-management-impl\src\test\resourc
es
- PersistenceUnit(name=pattern-managementPu, provider=null)
- JAVA AGENT NOT INSTALLED. The JPA Persistence Provider requested
installation of a ClassFileTransformer which requires a JavaAgent.  See
http://openejb.apache.org/3.0/javaagent.html
- Deployed
Application(path=C:\workspace\pattern-management\pattern-management-impl
\src\test\resources)
- OpenEJB ready.
OpenEJB ready.
Reply | Threaded
Open this post in threaded view
|

Re: OpenEJB - Missing required persistence.xml

Jacek Laskowski
On Feb 11, 2008 10:34 AM,  <[hidden email]> wrote:

> - FAIL ... PatternManagementDaoImpl:    Missing required persistence.xml
> for @PersistenceContext ref "em" to unit "pattern-managementPu"
>
> What's wrong? It is there. And where should it be placed? In META-INF
> like usually? It seems that it is later found.

"like usually"? That's how EJB3 spec mandates it so we should follow
the rule and we do. Can you jar -tf <your ejb/ear> and send the output
here? Could you show persistence.xml too so we can look at it?

> Can I define the order in which the EJB modules are loaded?

Not in a spec-compliant way. I'm not sure if you can do it in openejb
either, but would rather wait for Dave/Dain's reply before counting on
mine.

Jacek

--
Jacek Laskowski
http://www.JacekLaskowski.pl
Reply | Threaded
Open this post in threaded view
|

WG: OpenEJB - Missing required persistence.xml

Karsten.Ohme
In reply to this post by Karsten.Ohme
Hi,

I have attached a stripped down sample project, where the same error occurs: At first it fails because the persistence.xml is not found, later it is found. Also attached is the persistence.xml.

The output of jar -tf :

META-INF/
META-INF/MANIFEST.MF
foo/
foo/bar/
foo/bar/testfacade/
foo/bar/testfacade/model/
foo/bar/testfacade/model/Punkt.class
foo/bar/testfacade/model/Strecke.class
foo/bar/testfacade/TestFacade.class
foo/bar/testfacade/TestFacadeImpl.class
foo/bar/testfacade/TestFacadeImplOpenEJBTest.class
META-INF/persistence.xml
META-INF/maven/
META-INF/maven/TestFacade/
META-INF/maven/TestFacade/TestFacade/
META-INF/maven/TestFacade/TestFacade/pom.xml
META-INF/maven/TestFacade/TestFacade/pom.properties
META-INF/maven/org.apache.openejb/openejb-javaagent/pom.properties

Unfortunately I cannot send the whole project, the mail server is misconfigured and rejects it as spam.

The openejb.xml

<openejb>

        <Deployments dir="src/test/resources"/>
        <Deployments dir="target/classes" />

<Connector id="Default JDBC Database"  type="DataSource">
                #Embedded Derby example
                JdbcDriver org.apache.derby.jdbc.EmbeddedDriver
                JdbcUrl jdbc:derby:derbyDB;create=true</Connector>

</openejb>


Regards,
Karsten

-----Urspr√ľngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Jacek Laskowski
Gesendet: Montag, 11. Februar 2008 22:24
An: [hidden email]
Betreff: Re: OpenEJB - Missing required persistence.xml

On Feb 11, 2008 10:34 AM,  <[hidden email]> wrote:

> - FAIL ... PatternManagementDaoImpl:    Missing required persistence.xml
> for @PersistenceContext ref "em" to unit "pattern-managementPu"
>
> What's wrong? It is there. And where should it be placed? In META-INF
> like usually? It seems that it is later found.

"like usually"? That's how EJB3 spec mandates it so we should follow
the rule and we do. Can you jar -tf <your ejb/ear> and send the output
here? Could you show persistence.xml too so we can look at it?

> Can I define the order in which the EJB modules are loaded?

Not in a spec-compliant way. I'm not sure if you can do it in openejb
either, but would rather wait for Dave/Dain's reply before counting on
mine.

Jacek

--
Jacek Laskowski
http://www.JacekLaskowski.pl

persistence.xml (724 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: OpenEJB - Missing required persistence.xml

dblevins
Administrator
In reply to this post by Karsten.Ohme
It seems like what's happening is eclipse isn't configured to copy in  
the src/*/resources files into the related build output directories.

To see if I could replicate the issue, I grabbed our injection-of-
entitymanager example from the examples zip and generated an eclipse  
project for it using 'mvn eclipse:eclipse' on the command line.  Then  
I added the M2_REPO variable[1].  When it asked me if I wanted to  
rebuild everything I said yes.  After I was able to run the test case  
in eclipse.

Here's the relevant part of my .classpath file when all that was done:

   <classpathentry kind="src" path="src/main/java"/>
   <classpathentry kind="src" path="src/main/resources" excluding="**/
*.java"/>
   <classpathentry kind="src" path="src/test/java" output="target/test-
classes"/>
   <classpathentry kind="output" path="target/classes"/>

The goal is that "src/main/java" and "src/main/resources" should  
output into "target/classes".  And "src/test/java" and "src/test/
resources" should output into "target/test-classes".  If both of those  
happen correctly, you shouldn't need any <Deployments> entries in your  
openejb.xml file at all.

If you can post your .classpath file for pattern-management-impl  
that'd be great.

On a side note, you can configure data sources from within your test  
case (and delete your openejb.xml entirely) like so:

         Properties p = new Properties();
         p.put(Context.INITIAL_CONTEXT_FACTORY,  
"org.apache.openejb.client.LocalInitialContextFactory");

         p.put("myDataSource", "new://Connector?type=DataSource");
         p.put("myDataSource.JdbcDriver",  
"org.apache.derby.jdbc.EmbeddedDriver");
         p.put("myDataSource.JdbcUrl",  
"jdbc:derby:derbyDB;create=true");

         Context context = new InitialContext(p);

-David

[1]  http://people.apache.org/~dblevins/eclipse-howto/new-variable.tiff

On Feb 11, 2008, at 10:34 AM, <[hidden email]> <[hidden email]
 > wrote:

> Hi,
>
> I'm experimenting for one day with OpenEJB 3.0-beta-2, but I'm  
> stuck. I
> have tried different approaches to test EJBs, ejb3unit, JBoss
> embeddable, but OpenEJB seems to be the best, although it also does  
> not
> work for me.
>
> I always get a
>
> - FAIL ... PatternManagementDaoImpl: Missing required persistence.xml
> for @PersistenceContext ref "em" to unit "pattern-managementPu"
>
> What's wrong? It is there. And where should it be placed? In META-INF
> like usually? It seems that it is later found.
>
> What I want to do is to use an Apache Derby database (in memory) which
> is automatically initilialized. What do I have to define and where,  
> that
> this works?
>
> Can I define the order in which the EJB modules are loaded?
>
> Thanks,
> Karsten
>
> Apache OpenEJB 3.0-beta-2    build: 20080131-03:38
> http://openejb.apache.org/
> - openejb.home = C:\workspace\pattern-management\pattern-management-
> impl
> - openejb.base = C:\workspace\pattern-management\pattern-management-
> impl
> - Configuring Service(id=Default Security Service,  
> type=SecurityService,
> provider-id=Default Security Service)
> - Configuring Service(id=Default Transaction Manager,
> type=TransactionManager, provider-id=Default Transaction Manager)
> - Configuring Service(id=Derby Database, type=Resource,
> provider-id=Default JDBC Database)
> - Configuring Service(id=Default JDK 1.3 ProxyFactory,
> type=ProxyFactory, provider-id=Default JDK 1.3 ProxyFactory)
> - Configuring Service(id=Default Stateless Container, type=Container,
> provider-id=Default Stateless Container)
> - Found EjbModule in classpath:
> C:\workspace\pattern-management\pattern-management-impl\src\main
> \resourc
> es
> - Found EjbModule in classpath:
> C:\workspace\pattern-management\pattern-management-impl\src\test
> \resourc
> es
> - Configuring app:
> C:\workspace\networkstorage-management\networkstorage-management-impl
> \ta
> rget\classes
> - Loaded Module:
> C:\workspace\networkstorage-management\networkstorage-management-impl
> \ta
> rget\classes
> - Configuring app:
> C:\workspace\pattern-management\pattern-management-impl\target\classes
> - FAIL ... PatternManagementDaoImpl: Missing required persistence.xml
> for @PersistenceContext ref "em" to unit "pattern-managementPu"
> - FAIL ... TestFacadeImpl: Missing required persistence.xml for
> @PersistenceContext ref "em" to unit "pattern-managementPu"
> - Jar not loaded.
> C:\workspace\pattern-management\pattern-management-impl\target
> \classes.
> Module failed validation.
> AppModule(path=C:\workspace\pattern-management\pattern-management-
> impl\t
> arget\classes)
> - Configuring app:
> C:\workspace\pattern-management\pattern-management-impl\src\main
> \resourc
> es
> - Configuring PersistenceUnit(name=pattern-managementPu,  
> provider=null)
> - Loaded Module:
> C:\workspace\pattern-management\pattern-management-impl\src\main
> \resourc
> es
> - Configuring app:
> C:\workspace\pattern-management\pattern-management-impl\src\test
> \resourc
> es
> - Configuring PersistenceUnit(name=pattern-managementPu,  
> provider=null)
> - Loaded Module:
> C:\workspace\pattern-management\pattern-management-impl\src\test
> \resourc
> es
> - Creating ProxyFactory(id=Default JDK 1.3 ProxyFactory)
> - Creating TransactionManager(id=Default Transaction Manager)
> - Creating SecurityService(id=Default Security Service)
> - Creating Resource(id=Derby Database)
> - Creating Container(id=Default Stateless Container)
> - Assembling app:
> C:\workspace\networkstorage-management\networkstorage-management-impl
> \ta
> rget\classes
> - Jndi(name=NetworkStorageServiceImplRemote) -->
> Ejb(deployment-id=NetworkStorageServiceImpl)
> - Created Ejb(deployment-id=NetworkStorageServiceImpl,
> ejb-name=NetworkStorageServiceImpl, container=Default Stateless
> Container)
> - Deployed
> Application(path=C:\workspace\networkstorage-management
> \networkstorage-m
> anagement-impl\target\classes)
> - Assembling app:
> C:\workspace\pattern-management\pattern-management-impl\src\main
> \resourc
> es
> - PersistenceUnit(name=pattern-managementPu, provider=null)
> - JAVA AGENT NOT INSTALLED. The JPA Persistence Provider requested
> installation of a ClassFileTransformer which requires a JavaAgent.  
> See
> http://openejb.apache.org/3.0/javaagent.html
> - Deployed
> Application(path=C:\workspace\pattern-management\pattern-management-
> impl
> \src\main\resources)
> - Assembling app:
> C:\workspace\pattern-management\pattern-management-impl\src\test
> \resourc
> es
> - PersistenceUnit(name=pattern-managementPu, provider=null)
> - JAVA AGENT NOT INSTALLED. The JPA Persistence Provider requested
> installation of a ClassFileTransformer which requires a JavaAgent.  
> See
> http://openejb.apache.org/3.0/javaagent.html
> - Deployed
> Application(path=C:\workspace\pattern-management\pattern-management-
> impl
> \src\test\resources)
> - OpenEJB ready.
> OpenEJB ready.
>

Reply | Threaded
Open this post in threaded view
|

RE: OpenEJB - Missing required persistence.xml

Karsten.Ohme
In reply to this post by Karsten.Ohme
Hi,

Thanks for the answer. OK, I'm a step further. Your hint led me in the right direction.

At the moment I have problems with the database.

When I initialize my test case with:

    @Before
    public void initContext() throws Exception {
        Properties properties = new Properties();
        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
                "org.apache.openejb.client.LocalInitialContextFactory");

        if (DB_MODE == MYSQL) {
            properties.setProperty("Default\\ JDBC\\ Database.Password", "tpg");
            properties.setProperty("Default\\ JDBC\\ Database.JdbcUrl",
                    "jdbc:mysql://localhost:3306/tpg-server");
            properties.setProperty("Default\\ JDBC\\ Database.JdbcDriver",
                    "com.mysql.jdbc.Driver");
            properties.setProperty("Default\\ JDBC\\ Database.UserName", "tpg");
            properties.setProperty(
                    "Default\\ JDBC\\ Database.ConnectionInterface",
                    "javax.sql.DataSource");
        }
        if (DB_MODE == DERBY) {
            properties.setProperty("Default\\ JDBC\\ Database.JdbcUrl",
                    "jdbc:derby:derbyDB;create=true");
            properties.setProperty("Default\\ JDBC\\ Database.JdbcDriver",
                    "org.apache.derby.jdbc.EmbeddedDriver");
            properties.setProperty(
                    "Default\\ JDBC\\ Database.ConnectionInterface",
                    "javax.sql.DataSource");
        }

        InitialContext initialContext = new InitialContext(properties);
        Object ref = initialContext.lookup(TestFacadeImpl.class.getSimpleName()
                + "Remote");
        service = (TestFacade) ref;
    }

I get:

Apache OpenEJB 3.0-beta-2    build: 20080131-03:38
http://openejb.apache.org/
- openejb.home = C:\workspace\TestFacade\target
- openejb.base = C:\workspace\TestFacade\target
- Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
- Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
- Configuring Service(id=My DataSource, type=Resource, provider-id=Default JDBC Database)
- Configuring Service(id=My Unmanaged DataSource, type=Resource, provider-id=Default JDBC Database)
- Configuring Service(id=My JMS Resource Adapter, type=Resource, provider-id=Default JMS Resource Adapter)
- Configuring Service(id=My JMS Connection Factory, type=Resource, provider-id=Default JMS Connection Factory)
- Configuring Service(id=Default JDK 1.3 ProxyFactory, type=ProxyFactory, provider-id=Default JDK 1.3 ProxyFactory)
- Configuring Service(id=My CMP Container, type=Container, provider-id=Default CMP Container)
- Configuring Service(id=My BMP Container, type=Container, provider-id=Default BMP Container)
- Configuring Service(id=My Stateful Container, type=Container, provider-id=Default Stateful Container)
- Configuring Service(id=My Stateless Container, type=Container, provider-id=Default Stateless Container)
- Configuring Service(id=My MDB Container , type=Container, provider-id=Default MDB Container)
- Found EjbModule in classpath: C:\workspace\TestFacade\target\classes
- Configuring app: C:\workspace\TestFacade\target\classes
- Configuring PersistenceUnit(name=testFacadePu, provider=null)
- Loaded Module: C:\workspace\TestFacade\target\classes
- Creating ProxyFactory(id=Default JDK 1.3 ProxyFactory)
- Creating TransactionManager(id=Default Transaction Manager)
- Creating SecurityService(id=Default Security Service)
- Creating Resource(id=My DataSource)
- Creating Resource(id=My Unmanaged DataSource)
- Creating Resource(id=My JMS Resource Adapter)
- Creating Resource(id=My JMS Connection Factory)
- Creating ConnectionManager for Resource(id=My JMS Connection Factory)
- Creating Container(id=My CMP Container)
- Creating Container(id=My BMP Container)
- Creating Container(id=My Stateful Container)
- Creating Container(id=My Stateless Container)
- Creating Container(id=My MDB Container )
- Assembling app: C:\workspace\TestFacade\target\classes
- PersistenceUnit(name=testFacadePu, provider=null)
- Jndi(name=TestFacadeImplRemote) --> Ejb(deployment-id=TestFacadeImpl)
- Created Ejb(deployment-id=TestFacadeImpl, ejb-name=TestFacadeImpl, container=My Stateless Container)
- Deployed Application(path=C:\workspace\TestFacade\target\classes)
- OpenEJB ready.
OpenEJB ready.
- Unexpected exception from beforeCompletion; transaction will roll back
<openjpa-1.0.1-r420667:592145 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: null
        at org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.getConnection(AbstractJDBCSeq.java:162)
        at org.apache.openjpa.jdbc.kernel.TableJDBCSeq.allocateSequence(TableJDBCSeq.java:366)
        at org.apache.openjpa.jdbc.kernel.TableJDBCSeq.nextInternal(TableJDBCSeq.java:266)
        at org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.next(AbstractJDBCSeq.java:60)
        at org.apache.openjpa.util.ImplHelper.generateValue(ImplHelper.java:160)
        at org.apache.openjpa.util.ImplHelper.generateFieldValue(ImplHelper.java:144)
        at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignField(JDBCStoreManager.java:557)
        at org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:450)
        at org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:426)
        at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignObjectId(JDBCStoreManager.java:541)
        at org.apache.openjpa.kernel.DelegatingStoreManager.assignObjectId(DelegatingStoreManager.java:134)
        at org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerImpl.java:501)
        at org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2770)
        at org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:39)
        at org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:940)
        at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1892)
        at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1852)
        at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1770)
        at org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:514)
        at org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:499)
        at org.apache.geronimo.transaction.manager.TransactionImpl.beforePrepare(TransactionImpl.java:400)
        at org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:257)
        at org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit(TransactionManagerImpl.java:245)
        at org.apache.openejb.core.transaction.TransactionPolicy.commitTransaction(TransactionPolicy.java:141)
        at org.apache.openejb.core.transaction.TxRequired.afterInvoke(TxRequired.java:75)
        at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:233)
        at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:188)
        at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:165)
        at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:217)
        at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:77)
        at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:245)
        at org.apache.openejb.util.proxy.Jdk13InvocationHandler.invoke(Jdk13InvocationHandler.java:49)
        at $Proxy28.persistStrecke(Unknown Source)
        at foo.bar.testfacade.TestFacadeImplOpenEJBTest.testPersistStrecke(TestFacadeImplOpenEJBTest.java:58)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
        at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
        at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
        at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
        at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
        at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
        at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
        at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
        at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
        at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
        at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
        at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: javax.transaction.SystemException
        at org.apache.openjpa.ee.RegistryManagedRuntime$TransactionManagerRegistryFacade.suspend(RegistryManagedRuntime.java:176)
        at org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.getConnection(AbstractJDBCSeq.java:158)
        ... 55 more


For some strange reason when I was editing and using the openejb.xml the error was different; the tables in the database were not created.


Thanks,
Karsten

-----Urspr√ľngliche Nachricht-----
Von: David Blevins [mailto:[hidden email]]
Gesendet: Mittwoch, 13. Februar 2008 00:54
An: [hidden email]
Betreff: Re: OpenEJB - Missing required persistence.xml

It seems like what's happening is eclipse isn't configured to copy in  
the src/*/resources files into the related build output directories.

To see if I could replicate the issue, I grabbed our injection-of-
entitymanager example from the examples zip and generated an eclipse  
project for it using 'mvn eclipse:eclipse' on the command line.  Then  
I added the M2_REPO variable[1].  When it asked me if I wanted to  
rebuild everything I said yes.  After I was able to run the test case  
in eclipse.

Here's the relevant part of my .classpath file when all that was done:

   <classpathentry kind="src" path="src/main/java"/>
   <classpathentry kind="src" path="src/main/resources" excluding="**/
*.java"/>
   <classpathentry kind="src" path="src/test/java" output="target/test-
classes"/>
   <classpathentry kind="output" path="target/classes"/>

The goal is that "src/main/java" and "src/main/resources" should  
output into "target/classes".  And "src/test/java" and "src/test/
resources" should output into "target/test-classes".  If both of those  
happen correctly, you shouldn't need any <Deployments> entries in your  
openejb.xml file at all.

If you can post your .classpath file for pattern-management-impl  
that'd be great.

On a side note, you can configure data sources from within your test  
case (and delete your openejb.xml entirely) like so:

         Properties p = new Properties();
         p.put(Context.INITIAL_CONTEXT_FACTORY,  
"org.apache.openejb.client.LocalInitialContextFactory");

         p.put("myDataSource", "new://Connector?type=DataSource");
         p.put("myDataSource.JdbcDriver",  
"org.apache.derby.jdbc.EmbeddedDriver");
         p.put("myDataSource.JdbcUrl",  
"jdbc:derby:derbyDB;create=true");

         Context context = new InitialContext(p);

-David

[1]  http://people.apache.org/~dblevins/eclipse-howto/new-variable.tiff

On Feb 11, 2008, at 10:34 AM, <[hidden email]> <[hidden email]
 > wrote:

> Hi,
>
> I'm experimenting for one day with OpenEJB 3.0-beta-2, but I'm  
> stuck. I
> have tried different approaches to test EJBs, ejb3unit, JBoss
> embeddable, but OpenEJB seems to be the best, although it also does  
> not
> work for me.
>
> I always get a
>
> - FAIL ... PatternManagementDaoImpl: Missing required persistence.xml
> for @PersistenceContext ref "em" to unit "pattern-managementPu"
>
> What's wrong? It is there. And where should it be placed? In META-INF
> like usually? It seems that it is later found.
>
> What I want to do is to use an Apache Derby database (in memory) which
> is automatically initilialized. What do I have to define and where,  
> that
> this works?
>
> Can I define the order in which the EJB modules are loaded?
>
> Thanks,
> Karsten
>
> Apache OpenEJB 3.0-beta-2    build: 20080131-03:38
> http://openejb.apache.org/
> - openejb.home = C:\workspace\pattern-management\pattern-management-
> impl
> - openejb.base = C:\workspace\pattern-management\pattern-management-
> impl
> - Configuring Service(id=Default Security Service,  
> type=SecurityService,
> provider-id=Default Security Service)
> - Configuring Service(id=Default Transaction Manager,
> type=TransactionManager, provider-id=Default Transaction Manager)
> - Configuring Service(id=Derby Database, type=Resource,
> provider-id=Default JDBC Database)
> - Configuring Service(id=Default JDK 1.3 ProxyFactory,
> type=ProxyFactory, provider-id=Default JDK 1.3 ProxyFactory)
> - Configuring Service(id=Default Stateless Container, type=Container,
> provider-id=Default Stateless Container)
> - Found EjbModule in classpath:
> C:\workspace\pattern-management\pattern-management-impl\src\main
> \resourc
> es
> - Found EjbModule in classpath:
> C:\workspace\pattern-management\pattern-management-impl\src\test
> \resourc
> es
> - Configuring app:
> C:\workspace\networkstorage-management\networkstorage-management-impl
> \ta
> rget\classes
> - Loaded Module:
> C:\workspace\networkstorage-management\networkstorage-management-impl
> \ta
> rget\classes
> - Configuring app:
> C:\workspace\pattern-management\pattern-management-impl\target\classes
> - FAIL ... PatternManagementDaoImpl: Missing required persistence.xml
> for @PersistenceContext ref "em" to unit "pattern-managementPu"
> - FAIL ... TestFacadeImpl: Missing required persistence.xml for
> @PersistenceContext ref "em" to unit "pattern-managementPu"
> - Jar not loaded.
> C:\workspace\pattern-management\pattern-management-impl\target
> \classes.
> Module failed validation.
> AppModule(path=C:\workspace\pattern-management\pattern-management-
> impl\t
> arget\classes)
> - Configuring app:
> C:\workspace\pattern-management\pattern-management-impl\src\main
> \resourc
> es
> - Configuring PersistenceUnit(name=pattern-managementPu,  
> provider=null)
> - Loaded Module:
> C:\workspace\pattern-management\pattern-management-impl\src\main
> \resourc
> es
> - Configuring app:
> C:\workspace\pattern-management\pattern-management-impl\src\test
> \resourc
> es
> - Configuring PersistenceUnit(name=pattern-managementPu,  
> provider=null)
> - Loaded Module:
> C:\workspace\pattern-management\pattern-management-impl\src\test
> \resourc
> es
> - Creating ProxyFactory(id=Default JDK 1.3 ProxyFactory)
> - Creating TransactionManager(id=Default Transaction Manager)
> - Creating SecurityService(id=Default Security Service)
> - Creating Resource(id=Derby Database)
> - Creating Container(id=Default Stateless Container)
> - Assembling app:
> C:\workspace\networkstorage-management\networkstorage-management-impl
> \ta
> rget\classes
> - Jndi(name=NetworkStorageServiceImplRemote) -->
> Ejb(deployment-id=NetworkStorageServiceImpl)
> - Created Ejb(deployment-id=NetworkStorageServiceImpl,
> ejb-name=NetworkStorageServiceImpl, container=Default Stateless
> Container)
> - Deployed
> Application(path=C:\workspace\networkstorage-management
> \networkstorage-m
> anagement-impl\target\classes)
> - Assembling app:
> C:\workspace\pattern-management\pattern-management-impl\src\main
> \resourc
> es
> - PersistenceUnit(name=pattern-managementPu, provider=null)
> - JAVA AGENT NOT INSTALLED. The JPA Persistence Provider requested
> installation of a ClassFileTransformer which requires a JavaAgent.  
> See
> http://openejb.apache.org/3.0/javaagent.html
> - Deployed
> Application(path=C:\workspace\pattern-management\pattern-management-
> impl
> \src\main\resources)
> - Assembling app:
> C:\workspace\pattern-management\pattern-management-impl\src\test
> \resourc
> es
> - PersistenceUnit(name=pattern-managementPu, provider=null)
> - JAVA AGENT NOT INSTALLED. The JPA Persistence Provider requested
> installation of a ClassFileTransformer which requires a JavaAgent.  
> See
> http://openejb.apache.org/3.0/javaagent.html
> - Deployed
> Application(path=C:\workspace\pattern-management\pattern-management-
> impl
> \src\test\resources)
> - OpenEJB ready.
> OpenEJB ready.
>

Reply | Threaded
Open this post in threaded view
|

Re: OpenEJB - Missing required persistence.xml

Jacek Laskowski
On Feb 13, 2008 6:26 AM,  <[hidden email]> wrote:

> - Unexpected exception from beforeCompletion; transaction will roll back
> <openjpa-1.0.1-r420667:592145 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: null
>         at org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.getConnection(AbstractJDBCSeq.java:162)
>         at org.apache.openjpa.jdbc.kernel.TableJDBCSeq.allocateSequence(TableJDBCSeq.java:366)
>         at org.apache.openjpa.jdbc.kernel.TableJDBCSeq.nextInternal(TableJDBCSeq.java:266)
>         at org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.next(AbstractJDBCSeq.java:60)

I guess it's because of your invalid persistence.xml setting for
<jta-data-source>java:/DefaultDS</jta-data-source>. Did you change it?
I think it should be <jta-data-source>My DataSource</jta-data-source>.

Jacek


--
Jacek Laskowski
http://www.JacekLaskowski.pl
Reply | Threaded
Open this post in threaded view
|

Re: OpenEJB - Missing required persistence.xml

dblevins
Administrator
In reply to this post by Karsten.Ohme

On Feb 13, 2008, at 6:26 AM, <[hidden email]> <[hidden email]
 > wrote:

> I get:
>
> Apache OpenEJB 3.0-beta-2    build: 20080131-03:38
> http://openejb.apache.org/
> - openejb.home = C:\workspace\TestFacade\target
> - openejb.base = C:\workspace\TestFacade\target
> - Configuring Service(id=Default Security Service,  
> type=SecurityService, provider-id=Default Security Service)
> - Configuring Service(id=Default Transaction Manager,  
> type=TransactionManager, provider-id=Default Transaction Manager)
> - Configuring Service(id=My DataSource, type=Resource, provider-
> id=Default JDBC Database)
> - Configuring Service(id=My Unmanaged DataSource, type=Resource,  
> provider-id=Default JDBC Database)
> - Configuring Service(id=My JMS Resource Adapter, type=Resource,  
> provider-id=Default JMS Resource Adapter)
> - Configuring Service(id=My JMS Connection Factory, type=Resource,  
> provider-id=Default JMS Connection Factory)
> - Configuring Service(id=Default JDK 1.3 ProxyFactory,  
> type=ProxyFactory, provider-id=Default JDK 1.3 ProxyFactory)
> - Configuring Service(id=My CMP Container, type=Container, provider-
> id=Default CMP Container)
> - Configuring Service(id=My BMP Container, type=Container, provider-
> id=Default BMP Container)
> - Configuring Service(id=My Stateful Container, type=Container,  
> provider-id=Default Stateful Container)
> - Configuring Service(id=My Stateless Container, type=Container,  
> provider-id=Default Stateless Container)
> - Configuring Service(id=My MDB Container , type=Container, provider-
> id=Default MDB Container)
[...]
>
> For some strange reason when I was editing and using the openejb.xml  
> the error was different; the tables in the database were not created.
>

Based on that output, it looks like you've got a 'conf' directory  
under 'C:\workspace\TestFacade\target'.  When we see one of those, we  
unpack a complete setup of security, logging, and an openejb.xml  
file.  You can either delete the conf directory or simply put an  
openejb.xml file in there containing nothing more than "<openejb/>" as  
openejb will never overwrite it if it sees one is there (same with all  
the files in conf/).  If you delete the conf/ directory we try and  
tailor things a bit more for embedded testing; mostly shorter log  
lines with no date/time, as well we try and stop activemq and hsqldb  
from writing files to your disk that would have to be cleaned up  
manually.

>    @Before
>    public void initContext() throws Exception {
>        Properties properties = new Properties();
>        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
>                
> "org.apache.openejb.client.LocalInitialContextFactory");
>
>        if (DB_MODE == MYSQL) {
>            properties.setProperty("Default\\ JDBC\\  
> Database.Password", "tpg");
>            properties.setProperty("Default\\ JDBC\\ Database.JdbcUrl",
>                    "jdbc:mysql://localhost:3306/tpg-server");
>            properties.setProperty("Default\\ JDBC\\  
> Database.JdbcDriver",
>                    "com.mysql.jdbc.Driver");
>            properties.setProperty("Default\\ JDBC\\  
> Database.UserName", "tpg");
>            properties.setProperty(
>                    "Default\\ JDBC\\ Database.ConnectionInterface",
>                    "javax.sql.DataSource");
>        }
>        if (DB_MODE == DERBY) {
>            properties.setProperty("Default\\ JDBC\\ Database.JdbcUrl",
>                    "jdbc:derby:derbyDB;create=true");
>            properties.setProperty("Default\\ JDBC\\  
> Database.JdbcDriver",
>                    "org.apache.derby.jdbc.EmbeddedDriver");
>            properties.setProperty(
>                    "Default\\ JDBC\\ Database.ConnectionInterface",
>                    "javax.sql.DataSource");
>        }
>
>        InitialContext initialContext = new InitialContext(properties);
>        Object ref =  
> initialContext.lookup(TestFacadeImpl.class.getSimpleName()
>                + "Remote");
>        service = (TestFacade) ref;
>    }

That's a cool trick.  I never thought of doing that.  You need to  
remove the '\\' as java.util.Properties won't do any escaping on  
setProperties.  The escaping only happens when properties data is read  
from a text file or an xml -- and in each situation the escaping rules  
are different.

I'd definitely use the 'new://Resource' syntax i showed you and shy  
away from using "Default JDBC Database" as the resource name.  Reason  
being is that it will be much easier to see if your setup is working  
or not.  You could use the same name for your DERBY and MYSQL  
Resources, but I'd use different, more descriptive names so that it's  
easier to see with certainty via the log output which is getting used.

Something like this would be most reliable:

        if (DB_MODE == MYSQL) {
            properties.setProperty("MySqlDatabase", "new://Resource?
type=DataSource");
            properties.setProperty("MySqlDatabase.JdbcUrl",  
"jdbc:mysql://localhost:3306/tpg-server");
            properties.setProperty("MySqlDatabase.JdbcDriver",  
"com.mysql.jdbc.Driver");
            properties.setProperty("MySqlDatabase.UserName", "tpg");
            properties.setProperty("MySqlDatabase.Password", "tpg");
        } else if (DB_MODE == DERBY) {
            properties.setProperty("DerbyDatabase", "new://Resource?
type=DataSource");
            properties.setProperty("DerbyDatabase.JdbcUrl",  
"jdbc:derby:derbyDB;create=true");
            properties.setProperty("DerbyDatabase.JdbcDriver",  
"org.apache.derby.jdbc.EmbeddedDriver");
        }

That would give you the clearest log output and the most immediate  
feedback on what's going on.  We did have some issues in 3.0-beta-1  
that resulted in difficulty when people didn't use 'Default JDBC  
Database' as the name, but those were all fixed 3.0-beta-2.  Now it's  
highly encouraged not to use that name.

Note, I cut out the ConnectionInterface=javax.sql.DataSource property  
because that's the default for any <Resource> or <Connector> of  
type=DataSource.

On a similar note, the above syntax that goes "new://Resource?
type=DataSource" could also be specified as "new://Resource?
type=javax.sql.DataSource", or "new://Connector?type=DataSource", or  
"new://Connector?type=javax.DataSource".  It's fine to use whichever  
you like best.  Connector is an alias for Resource, and for the "type"  
attribute "DataSource" is an alias for "javax.sql.DataSource".

-David

Reply | Threaded
Open this post in threaded view
|

RE: OpenEJB - Missing required persistence.xml

Karsten.Ohme
In reply to this post by Karsten.Ohme
Thanks a lot again, I have now made one errors progress:

Now the problem seems to be that the entities in the database are not automatically created. Is this possible or do I have to do it on my own?

Thanks,
Karsten

javax.ejb.EJBException: The bean encountered a non-application exception.; nested exception is:
        <openjpa-1.0.1-r420667:592145 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Table 'tpg-server.strecke' doesn't exist {prepstmnt 5511938 SELECT t0.id, t0.name FROM strecke t0 WHERE (t0.name = ?) [params=(String) Meine Strecke]} [code=1146, state=42S02]
        at org.apache.openejb.core.ivm.BaseEjbProxyHandler.convertException(BaseEjbProxyHandler.java:366)
        at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:251)
        at org.apache.openejb.util.proxy.Jdk13InvocationHandler.invoke(Jdk13InvocationHandler.java:49)
        at $Proxy29.findStrecke(Unknown Source)
        at foo.bar.testfacade.TestFacadeImplOpenEJBTest.testFindStrecke(TestFacadeImplOpenEJBTest.java:108)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
        at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
        at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
        at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
        at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
        at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
        at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
        at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
        at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
        at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
        at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
        at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: <openjpa-1.0.1-r420667:592145 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Table 'tpg-server.strecke' doesn't exist {prepstmnt 5511938 SELECT t0.id, t0.name FROM strecke t0 WHERE (t0.name = ?) [params=(String) Meine Strecke]} [code=1146, state=42S02]
        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:851)
        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:773)
        at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:525)
        at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:237)
        at org.apache.openjpa.persistence.QueryImpl.getSingleResult(QueryImpl.java:300)
        at foo.bar.testfacade.TestFacadeImpl.findStrecke(TestFacadeImpl.java:40)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:146)
        at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:129)
        at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:67)
        at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:210)
        at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:188)
        at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:165)
        at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:217)
        at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:77)
        at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:245)
        ... 25 more
Caused by: java.lang.Exception: org.apache.openjpa.lib.jdbc.ReportingSQLException: Table 'tpg-server.strecke' doesn't exist {prepstmnt 5511938 SELECT t0.id, t0.name FROM strecke t0 WHERE (t0.name = ?) [params=(String) Meine Strecke]} [code=1146, state=42S02]
        at org.apache.openjpa.util.Exceptions.replaceNestedThrowables(Exceptions.java:242)
        at org.apache.openjpa.persistence.ArgumentException.writeObject(ArgumentException.java:107)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:917)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1339)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
        at org.apache.openejb.core.ivm.BaseEjbProxyHandler.copyObj(BaseEjbProxyHandler.java:508)
        at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:250)
        ... 25 more


Apache OpenEJB 3.0-beta-2    build: 20080131-03:38
http://openejb.apache.org/
INFO - openejb.home = C:\workspace\TestFacade\target
INFO - openejb.base = C:\workspace\TestFacade\target
WARN - Cannot find the configuration file [conf/openejb.xml].  Will attempt to create one for the beans deployed.
INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
INFO - Configuring Service(id=MySqlDatabase, type=Resource, provider-id=Default JDBC Database)
INFO - Configuring Service(id=Default JDK 1.3 ProxyFactory, type=ProxyFactory, provider-id=Default JDK 1.3 ProxyFactory)
INFO - Found EjbModule in classpath: C:\workspace\TestFacade\target\classes
INFO - Configuring app: C:\workspace\TestFacade\target\classes
INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container)
INFO - Auto-creating a container for bean TestFacadeImpl: Container(type=STATELESS, id=Default Stateless Container)
INFO - Configuring PersistenceUnit(name=testFacadePu, provider=null)
INFO - Loaded Module: C:\workspace\TestFacade\target\classes
INFO - Assembling app: C:\workspace\TestFacade\target\classes
INFO - PersistenceUnit(name=testFacadePu, provider=null)
INFO - Jndi(name=TestFacadeImplRemote) --> Ejb(deployment-id=TestFacadeImpl)
INFO - Created Ejb(deployment-id=TestFacadeImpl, ejb-name=TestFacadeImpl, container=Default Stateless Container)
INFO - Deployed Application(path=C:\workspace\TestFacade\target\classes)
INFO - OpenEJB ready.
OpenEJB ready.
WARN - Unexpected exception from beforeCompletion; transaction will roll back
<openjpa-1.0.1-r420667:592145 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: null
        at org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.getConnection(AbstractJDBCSeq.java:162)
        at org.apache.openjpa.jdbc.kernel.TableJDBCSeq.allocateSequence(TableJDBCSeq.java:366)
        at org.apache.openjpa.jdbc.kernel.TableJDBCSeq.nextInternal(TableJDBCSeq.java:266)
        at org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.next(AbstractJDBCSeq.java:60)
        at org.apache.openjpa.util.ImplHelper.generateValue(ImplHelper.java:160)
        at org.apache.openjpa.util.ImplHelper.generateFieldValue(ImplHelper.java:144)
        at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignField(JDBCStoreManager.java:557)
        at org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:450)
        at org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:426)
        at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignObjectId(JDBCStoreManager.java:541)
        at org.apache.openjpa.kernel.DelegatingStoreManager.assignObjectId(DelegatingStoreManager.java:134)
        at org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerImpl.java:501)
        at org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2770)
        at org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:39)
        at org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:940)
        at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1892)
        at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1852)
        at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1770)
        at org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:514)
        at org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:499)
        at org.apache.geronimo.transaction.manager.TransactionImpl.beforePrepare(TransactionImpl.java:400)
        at org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:257)
        at org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit(TransactionManagerImpl.java:245)
        at org.apache.openejb.core.transaction.TransactionPolicy.commitTransaction(TransactionPolicy.java:141)
        at org.apache.openejb.core.transaction.TxRequired.afterInvoke(TxRequired.java:75)
        at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:233)
        at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:188)
        at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:165)
        at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:217)
        at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:77)
        at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:245)
        at org.apache.openejb.util.proxy.Jdk13InvocationHandler.invoke(Jdk13InvocationHandler.java:49)
        at $Proxy29.persistStrecke(Unknown Source)
        at foo.bar.testfacade.TestFacadeImplOpenEJBTest.testPersistStrecke(TestFacadeImplOpenEJBTest.java:103)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
        at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
        at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
        at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
        at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
        at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
        at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
        at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
        at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
        at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
        at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
        at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: javax.transaction.SystemException
        at org.apache.openjpa.ee.RegistryManagedRuntime$TransactionManagerRegistryFacade.suspend(RegistryManagedRuntime.java:176)
        at org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.getConnection(AbstractJDBCSeq.java:158)
        ... 55 more
Reply | Threaded
Open this post in threaded view
|

Re: OpenEJB - Missing required persistence.xml

Jacek Laskowski
On Thu, Feb 14, 2008 at 6:29 AM,  <[hidden email]> wrote:

>  Now the problem seems to be that the entities in the database are not automatically created. Is this possible or do I have to do it on my own?

What do you mean by "not automatically created"? If you execute
EntityManager.persist() method they should be there. If they are not,
that's the issue. Without persist you should not expect to see any
entities in the db unless you execute sql scripts or something to put
them in.

Jacek

--
Jacek Laskowski
http://www.JacekLaskowski.pl
Reply | Threaded
Open this post in threaded view
|

Re: OpenEJB - Missing required persistence.xml

dblevins
Administrator
In reply to this post by Karsten.Ohme

On Feb 14, 2008, at 6:29 AM, <[hidden email]> <[hidden email]
 > wrote:

> Thanks a lot again, I have now made one errors progress:
>
> Now the problem seems to be that the entities in the database are  
> not automatically created. Is this possible or do I have to do it on  
> my own?
>
> Thanks,
> Karsten
>
> javax.ejb.EJBException: The bean encountered a non-application  
> exception.; nested exception is:
> <openjpa-1.0.1-r420667:592145 nonfatal user error>  
> org.apache.openjpa.persistence.ArgumentException: Table 'tpg-
> server.strecke' doesn't exist {prepstmnt 5511938 SELECT t0.id,  
> t0.name FROM strecke t0 WHERE (t0.name = ?) [params=(String) Meine  
> Strecke]} [code=1146, state=42S02]

Excellent.  You're through all the hard stuff.  This error here is  
because the tables don't exist, which is very easy to fix.  In your  
persistence.xml file add the following OpenJPA specific property:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"  
version="1.0">

   <persistence-unit name="movie-unit">
     <!-- your other stuff -->

     <properties>
       <property name="openjpa.jdbc.SynchronizeMappings"  
value="buildSchema(ForeignKeys=true)"/>
     </properties>
   </persistence-unit>
</persistence>

What this is going to do is tell OpenJPA to auto-create all your  
tables, all your primary keys and all foreign keys exactly to match  
your objects. A very excellent feature indeed.

You should be all set.

A warning in advance for any new JPA user, by default all objects will  
detach at the end of a transaction; people typically discover this  
when the go to remove or update an object they fetched previously and  
get an exception like "You cannot perform operation delete on detached  
object".  The part that's sneaky is that a test case has no  
transaction, so unless specified otherwise a transaction will start  
and complete around each ejb method call and then as a result  
persistent objects passed back as return values will detach.

There are a couple ways to deal with that.

The first is to use PersistenceContextType.EXTENDED for EntityManager  
refs instead of the default of PersistenceContextType.TRANSACTION.  
The "injection-of-entitymanager" example in our examples zip shows how  
to do that.  (it's also available here: http://svn.apache.org/repos/asf/openejb/tags/openejb-3.0-beta-2/examples/injection-of-entitymanager/)

The second is to use a technique to execute transactions in your test  
code.  That's described here:  http://openejb.apache.org/3.0/unit-testing-transactions.html


-David

Reply | Threaded
Open this post in threaded view
|

Re: OpenEJB - Missing required persistence.xml

Karsten.Ohme
In reply to this post by Karsten.Ohme
Not working, the tables are not created. Now I get this:

Auto-commit can not be set while enrolled in a transaction

javax.ejb.EJBException: The bean encountered a non-application exception.; nested exception is:
        <openjpa-1.0.1-r420667:592145 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: Auto-commit can not be set while enrolled in a transaction
        at org.apache.openejb.core.ivm.BaseEjbProxyHandler.convertException(BaseEjbProxyHandler.java:366)
        at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:251)
        at org.apache.openejb.util.proxy.Jdk13InvocationHandler.invoke(Jdk13InvocationHandler.java:49)
        at $Proxy29.persistStrecke(Unknown Source)
        at foo.bar.testfacade.TestFacadeImplOpenEJBTest.testPersistStrecke(TestFacadeImplOpenEJBTest.java:103)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
        at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
        at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
        at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
        at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
        at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
        at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
        at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
        at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
        at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
        at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
        at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: <openjpa-1.0.1-r420667:592145 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: Auto-commit can not be set while enrolled in a transaction
        at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:549)
        at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:449)
        at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:170)
        at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(JDBCBrokerFactory.java:130)
        at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:186)
        at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142)
        at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192)
        at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:56)
        at org.apache.openejb.persistence.JtaEntityManagerRegistry.getEntityManager(JtaEntityManagerRegistry.java:105)
        at org.apache.openejb.persistence.JtaEntityManager.getEntityManager(JtaEntityManager.java:61)
        at org.apache.openejb.persistence.JtaEntityManager.persist(JtaEntityManager.java:97)
        at foo.bar.testfacade.TestFacadeImpl.persistStrecke(TestFacadeImpl.java:49)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:146)
        at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:129)
        at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:67)
        at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:210)
        at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:188)
        at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:165)
        at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:217)
        at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:77)
        at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:245)
        ... 25 more
Caused by: java.lang.Exception: java.sql.SQLException: Auto-commit can not be set while enrolled in a transaction
        at org.apache.openjpa.util.Exceptions.replaceNestedThrowables(Exceptions.java:242)
        at org.apache.openjpa.persistence.PersistenceException.writeObject(PersistenceException.java:100)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:917)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1339)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
        at org.apache.openejb.core.ivm.BaseEjbProxyHandler.copyObj(BaseEjbProxyHandler.java:508)
        at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:250)
        ... 25 more

Reply | Threaded
Open this post in threaded view
|

Re: OpenEJB - Missing required persistence.xml

Karsten.Ohme
In reply to this post by Karsten.Ohme
Hi,

well it works now. Because I have changed the persistence provider to Hibernate. The problem now is that entities are not persisted. persist() simply does nothing. But no error is shown.

The persistence.xml is as follows. I have also a full log of the whole Hibernate. I cannot find an error.

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
        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">
        <persistence-unit name="testFacadePu" transaction-type="RESOURCE_LOCAL">
                <provider>org.hibernate.ejb.HibernatePersistence</provider>
                <non-jta-data-source>java:jdbc/DerbyDatabase</non-jta-data-source>
                <properties>
  <property name="hibernate.hbm2ddl.auto" value="create-drop" />
                        <property name="openjpa.jdbc.SynchronizeMappings"
                                value="buildSchema(ForeignKeys=true)" />
                        <property name="hibernate.hbm2ddl.auto" value="create-drop" />
                </properties>
        </persistence-unit>
</persistence>

The log:

DEBUG - opened session at timestamp: 12030966900
DEBUG - id unsaved-value: 0
DEBUG - transient instance of: foo.bar.testfacade.model.Strecke
DEBUG - saving transient instance
DEBUG - saving [foo.bar.testfacade.model.Strecke#<null>]
DEBUG - processing cascade ACTION_PERSIST for: foo.bar.testfacade.model.Strecke
DEBUG - done processing cascade ACTION_PERSIST for: foo.bar.testfacade.model.Strecke
DEBUG - Wrapped collection in role: foo.bar.testfacade.model.Strecke.punkte
DEBUG - delaying identity-insert due to no transaction in progress
DEBUG - processing cascade ACTION_PERSIST for: foo.bar.testfacade.model.Strecke
DEBUG - cascade ACTION_PERSIST for collection: foo.bar.testfacade.model.Strecke.punkte
DEBUG - cascading to persist: foo.bar.testfacade.model.Punkt
DEBUG - id unsaved-value: 0
DEBUG - transient instance of: foo.bar.testfacade.model.Punkt
DEBUG - saving transient instance
DEBUG - saving [foo.bar.testfacade.model.Punkt#<null>]
DEBUG - delaying identity-insert due to no transaction in progress
DEBUG - cascading to persist: foo.bar.testfacade.model.Punkt
DEBUG - id unsaved-value: 0
DEBUG - transient instance of: foo.bar.testfacade.model.Punkt
DEBUG - saving transient instance
DEBUG - saving [foo.bar.testfacade.model.Punkt#<null>]
DEBUG - delaying identity-insert due to no transaction in progress
DEBUG - cascading to persist: foo.bar.testfacade.model.Punkt
DEBUG - id unsaved-value: 0
DEBUG - transient instance of: foo.bar.testfacade.model.Punkt
DEBUG - saving transient instance
DEBUG - saving [foo.bar.testfacade.model.Punkt#<null>]
DEBUG - delaying identity-insert due to no transaction in progress
DEBUG - cascading to persist: foo.bar.testfacade.model.Punkt
DEBUG - id unsaved-value: 0
DEBUG - transient instance of: foo.bar.testfacade.model.Punkt
DEBUG - saving transient instance
DEBUG - saving [foo.bar.testfacade.model.Punkt#<null>]
DEBUG - delaying identity-insert due to no transaction in progress
DEBUG - cascading to persist: foo.bar.testfacade.model.Punkt
DEBUG - id unsaved-value: 0
DEBUG - transient instance of: foo.bar.testfacade.model.Punkt
DEBUG - saving transient instance
DEBUG - saving [foo.bar.testfacade.model.Punkt#<null>]
DEBUG - delaying identity-insert due to no transaction in progress
DEBUG - done cascade ACTION_PERSIST for collection: foo.bar.testfacade.model.Strecke.punkte
DEBUG - done processing cascade ACTION_PERSIST for: foo.bar.testfacade.model.Strecke
DEBUG - closing session
DEBUG - connection already null in cleanup : no action
Reply | Threaded
Open this post in threaded view
|

Re: OpenEJB - Missing required persistence.xml

Jacek Laskowski
On Fri, Feb 15, 2008 at 9:36 AM,  <[hidden email]> wrote:

>  <?xml version="1.0" encoding="UTF-8"?>
>  <persistence version="1.0"
>
>         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">
>         <persistence-unit name="testFacadePu" transaction-type="RESOURCE_LOCAL">
>                 <provider>org.hibernate.ejb.HibernatePersistence</provider>

Remove provider so OpenJPA kicks in. It actually did, but provider
might confuse it or openejb. Don't really know. Add <jta-data-source>
with the same value as <non-jta-data-source>. Remove transaction-type
element.

What's in foo.bar.testfacade.TestFacadeImplOpenEJBTest.testPersistStrecke(TestFacadeImplOpenEJBTest.java:103)?

Jacek

--
Jacek Laskowski
http://www.JacekLaskowski.pl
Reply | Threaded
Open this post in threaded view
|

Re: OpenEJB - Missing required persistence.xml

dblevins
Administrator
In reply to this post by Karsten.Ohme

On Feb 15, 2008, at 4:03 AM, <[hidden email]> <[hidden email]
 > wrote:

> Not working, the tables are not created. Now I get this:
>
> Auto-commit can not be set while enrolled in a transaction
>

I'm very interested in how you got this error so I can fix any related  
checks we have.  In 3.0-beta-2 I attempted to make it impossible to  
get this error -- apparently unsuccessfully :)

Info that will help:
  - the persistence.xml
  - let me know if you're using PersistenceContextType.TRANSACTION  
(default) or PersistenceContextType.EXTENDED in your  
@PersistenceContext annotation
  - the openejb log output so I can see what kind of configuration  
ended up getting used.
  - your test setup code


The "Auto-commit" error usually means is that either a) only the jta-
data-source is configured in your persistence.xml so OpenJPA  
incorrectly attempts to use it also as an non-jta-data-source, or b)  
the non-jta-data-source specified is actually a jta-data-source (i.e.  
a Resource where the 'JtaManaged' property isn't set to 'false')

In 3.0-beta-2 it's impossible to set jta-data-source to a  
JtaManaged=false Resource or to set the non-jta-data-source to a  
JtaManaged=true Resource.  Also, if you don't supply either jta-data-
source or non-jta-data-source, we will create Resources for you with  
their JtaManaged property set accordingly, and set them as the value  
of jta-data-source or non-jta-data-source, so it's also impossible to  
not have them filled in as we will fill them in when you haven't.  The  
thing I've noticed in the code now is that our "make a managed/
unmanaged datasource for you" code could be smarter and needs to be  
improved -- it should take the one you defined (if there is one), copy  
it, set the JtaManaged flag accordingly, then use that.

As an FYI, I've been taking all these exchanges and using them to help  
fill out the docs:

   http://cwiki.apache.org/OPENEJBx30/jpa-usage.html
   http://cwiki.apache.org/OPENEJBx30/openjpa.html

I have an empty Hibernate doc waiting in the wing:

   http://cwiki.apache.org/OPENEJBx30/hibernate.html

-David

Reply | Threaded
Open this post in threaded view
|

Re: OpenEJB - Missing required persistence.xml

Jacek Laskowski
On Feb 15, 2008 2:37 PM, David Blevins <[hidden email]> wrote:

> The "Auto-commit" error usually means is that either a) only the jta-
> data-source is configured in your persistence.xml so OpenJPA
> incorrectly attempts to use it also as an non-jta-data-source, or b)
> the non-jta-data-source specified is actually a jta-data-source (i.e.
> a Resource where the 'JtaManaged' property isn't set to 'false')

Hi Dave,

He had non-jta-data-source only so I think his scenario's b).

Jacek

--
Jacek Laskowski
http://www.JacekLaskowski.pl
Reply | Threaded
Open this post in threaded view
|

Re: OpenEJB - Missing required persistence.xml

dblevins
Administrator
In reply to this post by Karsten.Ohme

On Feb 15, 2008, at 9:36 AM, <[hidden email]> <[hidden email]
 > wrote:

> Hi,
>
> well it works now. Because I have changed the persistence provider  
> to Hibernate. The problem now is that entities are not persisted.  
> persist() simply does nothing. But no error is shown.
>
> The persistence.xml is as follows. I have also a full log of the  
> whole Hibernate. I cannot find an error.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence version="1.0"
> 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 
> ">
> <persistence-unit name="testFacadePu" transaction-
> type="RESOURCE_LOCAL">
> <provider>org.hibernate.ejb.HibernatePersistence</provider>
> <non-jta-data-source>java:jdbc/DerbyDatabase</non-jta-data-source>
> <properties>
>   <property name="hibernate.hbm2ddl.auto" value="create-drop" />
> <property name="openjpa.jdbc.SynchronizeMappings"
> value="buildSchema(ForeignKeys=true)" />
> <property name="hibernate.hbm2ddl.auto" value="create-drop" />
> </properties>
> </persistence-unit>
> </persistence>

I'd definitely use transaction-type="TRANSACTION" instead of  
transaction-type="RESOURCE_LOCAL" with either OpenJPA or Hibernate.  
RESOURCE_LOCAL is very difficult to use and transaction-
type="TRANSACTION" is not slow like people normally think.  At the  
very least, start with the default of transaction-type="TRANSACTION",  
get that to work and switch it later if it's still important.

Regardless of if you use transaction-type="RESOURCE_LOCAL" or  
transaction-type="TRANSACTION" you definitely should supply both <jta-
data-source> and <non-jta-data-source>.

The DataSource for the jta-data-source should always have it's  
'JtaManaged' property set to 'true' (this is the default)
The DataSource for the non-jta-data-source should always have it's  
'JtaManaged' property set to 'false'.

In your test code, you could do it like this:


       if (DB_MODE == MYSQL) {
           properties.setProperty("MySqlDatabase", "new://Resource?
type=DataSource");
           properties.setProperty("MySqlDatabase.JdbcUrl",  
"jdbc:mysql://localhost:3306/tpg-server");
           properties.setProperty("MySqlDatabase.JdbcDriver",  
"com.mysql.jdbc.Driver");
           properties.setProperty("MySqlDatabase.UserName", "tpg");
           properties.setProperty("MySqlDatabase.Password", "tpg");

           properties.setProperty("MySqlDatabaseUnmanaged", "new://
Resource?type=DataSource");
           properties.setProperty("MySqlDatabaseUnmanaged.JdbcUrl",  
"jdbc:mysql://localhost:3306/tpg-server");
           properties.setProperty("MySqlDatabaseUnmanaged.JdbcDriver",  
"com.mysql.jdbc.Driver");
           properties.setProperty("MySqlDatabaseUnmanaged.UserName",  
"tpg");
           properties.setProperty("MySqlDatabaseUnmanaged.Password",  
"tpg");
           properties.setProperty("MySqlDatabaseUnmanaged.JtaManaged",  
"false");
       } else if (DB_MODE == DERBY) {
           properties.setProperty("DerbyDatabase", "new://Resource?
type=DataSource");
           properties.setProperty("DerbyDatabase.JdbcUrl",  
"jdbc:derby:derbyDB;create=true");
           properties.setProperty("DerbyDatabase.JdbcDriver",  
"org.apache.derby.jdbc.EmbeddedDriver");

           properties.setProperty("DerbyDatabaseUnmanaged", "new://
Resource?type=DataSource");
           properties.setProperty("DerbyDatabaseUnmanaged.JdbcUrl",  
"jdbc:derby:derbyDB;create=true");
           properties.setProperty("DerbyDatabaseUnmanaged.JdbcDriver",  
"org.apache.derby.jdbc.EmbeddedDriver");
           properties.setProperty("DerbyDatabaseUnmanaged.JtaManaged",  
"false");
       }


-David


Reply | Threaded
Open this post in threaded view
|

Re: OpenEJB - Missing required persistence.xml

dblevins
Administrator
In reply to this post by Jacek Laskowski

On Feb 15, 2008, at 2:46 PM, Jacek Laskowski wrote:

> On Feb 15, 2008 2:37 PM, David Blevins <[hidden email]> wrote:
>
>> The "Auto-commit" error usually means is that either a) only the jta-
>> data-source is configured in your persistence.xml so OpenJPA
>> incorrectly attempts to use it also as an non-jta-data-source, or b)
>> the non-jta-data-source specified is actually a jta-data-source (i.e.
>> a Resource where the 'JtaManaged' property isn't set to 'false')
>
> Hi Dave,
>
> He had non-jta-data-source only so I think his scenario's b).

As I described both a) and b) should be impossible in 3.0-beta-2, so  
I'm still very baffled.  Has to be something else.

-David

Reply | Threaded
Open this post in threaded view
|

Re: OpenEJB - Missing required persistence.xml

Karsten Ohme
In reply to this post by Karsten.Ohme
 >On Fri, Feb 15, 2008 at 9:36 AM,  <Karsten.Ohme@...> wrote:
 >
 >>  <?xml version="1.0" encoding="UTF-8"?>
 >>  <persistence version="1.0"
 >>
 >>         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">
 >>         <persistence-unit name="testFacadePu"
 >transaction-type="RESOURCE_LOCAL">
 >>
 ><provider>org.hibernate.ejb.HibernatePersistence</provider>
 >
 >Remove provider so OpenJPA kicks in. It actually did, but provider
 >might confuse it or openejb. Don't really know. Add <jta-data-source>
 >with the same value as <non-jta-data-source>. Remove transaction-type
 >element.

OpenJPA was not working, so I had to use Hibernate. I would also like to
use Hibernate, because the final persistence layer should be Hibernate.
There also some older Springs dependencies, so if the database layout is
not 100 % identical it does matter.

The transaction type element was necessary because of an error with
Hibernate:

See JTA Transaction Manager topic at
http://www.abcseo.com/tech/java/jboss-ebj-troubleshooting

 >What's in
 >foo.bar.testfacade.TestFacadeImplOpenEJBTest.testPersistStrecke(TestFacadeImplOpenEJBTest.java:103)?

It is a call to a stateless bean. The Bean call persist() like this :

public void persistStrecke(Strecke s) {
  em.persist(s)
}

 >Jacek
 >
 >--
 >Jacek Laskowski
 >http://www.JacekLaskowski.pl

Thanks,
Karsten


Reply | Threaded
Open this post in threaded view
|

Re: OpenEJB - Missing required persistence.xml

Karsten Ohme
In reply to this post by Karsten.Ohme

> On Feb 15, 2008, at 2:46 PM, Jacek Laskowski wrote:
>
>  > On Feb 15, 2008 2:37 PM, David Blevins <david.blevins@...> wrote:
>  >
>  >> The "Auto-commit" error usually means is that either a) only the jta-
>  >> data-source is configured in your persistence.xml so OpenJPA
>  >> incorrectly attempts to use it also as an non-jta-data-source, or b)
>  >> the non-jta-data-source specified is actually a jta-data-source (i.e.
>  >> a Resource where the 'JtaManaged' property isn't set to 'false')
>  >
>  > Hi Dave,
>  >
>  > He had non-jta-data-source only so I think his scenario's b).
> ... [show rest of quote]
>
> As I described both a) and b) should be impossible in 3.0-beta-2, so
> I'm still very baffled.  Has to be something else.

I will try again to send the source code as zipped attachment. The last
times it was always impossible, because it was considered as spam. I
will have access to the source on Monday again.

Thanks,
Karsten

>
> -David
>

Reply | Threaded
Open this post in threaded view
|

Re: OpenEJB - Missing required persistence.xml

dblevins
Administrator

On Feb 16, 2008, at 1:22 PM, Karsten Ohme wrote:

>
>> On Feb 15, 2008, at 2:46 PM, Jacek Laskowski wrote:
>> > On Feb 15, 2008 2:37 PM, David Blevins <david.blevins@...> wrote:
>> >
>> >> The "Auto-commit" error usually means is that either a) only the  
>> jta-
>> >> data-source is configured in your persistence.xml so OpenJPA
>> >> incorrectly attempts to use it also as an non-jta-data-source,  
>> or b)
>> >> the non-jta-data-source specified is actually a jta-data-source  
>> (i.e.
>> >> a Resource where the 'JtaManaged' property isn't set to 'false')
>> >
>> > Hi Dave,
>> >
>> > He had non-jta-data-source only so I think his scenario's b).
>> ... [show rest of quote]
>> As I described both a) and b) should be impossible in 3.0-beta-2, so
>> I'm still very baffled.  Has to be something else.
>
> I will try again to send the source code as zipped attachment. The  
> last times it was always impossible, because it was considered as  
> spam. I will have access to the source on Monday again.

Great.  You can attach it here: http://issues.apache.org/jira/browse/OPENEJB-755

Sometimes the list refuses to accept attachments.

-David

12