ObjectDB ObjectDB

How to package orm.xml when using EJB in WAR?



I have database utility classes in one project, the id's use sequences declared in an orm.xml file for example:

<entity class="com.x.y.z.model.Unit">
            <id name="unitId">
                <column name="unit_id" />
                <generated-value strategy="SEQUENCE" generator="unit_seq"/>
                <sequence-generator name="unit_seq" sequence-name = "oe.seq_unit_id" allocation-size = "1" />

and the persistence.xml references this orm.xml :

<persistence-unit name="OBJECT_DB_LOCAL_PU" transaction-type="JTA">
            <property name="javax.persistence.jdbc.url" value="$objectdb/db/gdm.odb"/>
            <property name="javax.persistence.jdbc.user" value="admin"/>
            <property name="javax.persistence.jdbc.password" value="admin"/>

both persistence.xml and orm.xml are located in src/main/resources/META-INF and Maven correctly copies META-INF and all contents into the root of jar file when the (EJB) project is built.

When that EJB is deployed to e.g. GlassFish 3.1.1 all apperar to be OK, and a singleton annotated with @Startup can access the database OK for both read and write, suggesting that the orm.xml is found OK and that the sequences are declared properly (they also work for postgres).

However, when a different web project (WAR file), which declares a dependency to the database EJB is built and deployed, this error message pops up:

Caused by: com.objectdb.o._PersistenceException: Failed to read a resource '/META-INF/orm.xml' (referenced from persistence.xml)

One partial work-around seems to be to add a copy of orm.xml into src/main/resources/META-INF of the web project that depends on the EJB .. but it's not great to have duplicate copies of the file, and this isn't needed for other persistence providers, e.g. EclipseLink, which can pick up the orm.xml from the jar file embedded in the war file OK.

However, even when duplicating the orm.xml, a different error pops up:

WARNING: DTX5014: Caught exception in beforeCompletion() callback:
[ObjectDB 2.2.9_08] javax.persistence.PersistenceException
Invalid null value in non optional field unitId (error 648)

which seems to imply that the sequence generator isn't working when the EJB is embedded in a WAR file?






Please check the attached NetBeans project.

It is based on the Java EE guestbook tutorial with the following changes:

  • It is a parent project with 2 sub projects - an ejb module and a war module.
  • Guest ids are allocated by a sequence that is defined in the orm.xml file.

It seems to work fine - the sequence definition in the orm.xml file specifies initial-value="777" and guest ids are allocated as expected starting 778.

To run it you will have to resolve/add the objectdb-jee.jar in the ejb project.

If there is still a problem - try to demonstrate it by changing the attached project.

ObjectDB Support


To post on this website please sign in.