ObjectDB ObjectDB

mapping file is not being loaded

#1

Hi, I am evaluating ObjectDB by using it with an in-house developed library in order to prototype its capabilities / performance.

I am having a problem in that the in-house library in question reads a simple configuration file to determine available persistence units, and then bootstraps them using the JPA Persistance.createEntityManagerFactory() method and passing in the persistence unit name (again, obtained from the configuration file ).

After the entity manager factory is obtained, the Metamodel is empty - none of the entities referenced in the mapping file are present in the Metamodel.

 

here is my persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
             http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">                         
    <persistence-unit name="project.odb" >
        <mapping-file>mil/navy/navo/arf/config/orm.xml</mapping-file>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>
            <property name="javax.persistence.jdbc.url" value="objectdb://localhost:6136/project.odb" />
            <property name="javax.persistence.jdbc.user" value="admin"/>
            <property name="javax.persistence.jdbc.password" value="admin" />
        </properties>
    </persistence-unit>
</persistence>

 

The entities are mapped in the ORM.xml file correctly, as they work with the previous hibernate implementation.

the java code that interacts with the Persistence api:

EntityManagerFactory emf = Persistence.createEntitManagerFactory("project.odb");

//this set is alwasy empty with ObjectDB
Set<EntityType> managedEntities = emf.getMetaModel().getEntities();

 

I am certain that this must be a configuration issue, although I am using the default configuration file with no changes.

 

 

 

edit
delete
#2

Please check if listing the entity classes in the persistence.xml file makes any difference.

Another thing to check - setting exclude-unlisted-classes to false rather than true.

ObjectDB Support
edit
delete
#3

After being pulled away from this project for a few months, I have been able to (finally) return and attempt to address this issue.  I have followed both suggestions - manually listing classes along with setting exclude-unlisted-classes to false.

The Metamodel API still returns the empty set when 'getEntities()' is invoked.

The prototype is running in a  Tomcat server with a RESOURCE_LOCAL transaction scope over a plain JDBC connection.

The entity classes use no JPA annotations, as some of our internal guidelines call for the xml mapping files only, and this is an important requirement.

ObjectDB itself is running in client-server mode using configuration contained in the default location (objectdb root directory).

Both objectdb.jar and objectdb-jee.jar are on the classpath.

Finally, the application prototype is being deployed as a war, with objectdb jars on the WAR lib directory.

Any suggestions would be appreciated.

 

 

edit
delete
#4

Try changing the unit name from project.odb to project, to see if the persistence unit is found.

The special odb suffix is interpreted by ObjectDB also as a direct database path, so if the persistence unit is not found a virtual persistence unit is used and no error is produced.

Did you try anything else except using the Metamodel API (storing objects, etc)? Does it work?

ObjectDB Support
edit
delete
#5

So I changed the persistence unit name by removing the .odb extension, and then wrote a simple unit test that created one of my project's entity classes and persisted it.  After running the unit test, the Metamodel data for any other entity class that was reachable from the one I persisted was available via the Metamodel API.  I then removed the explicit class listings, and re-set the exclude-unlisted-classes configuration element back to false, and ran the original project.  The metadata was now accessible.

So it appears then that Metamodel for a given Entity is unavailable until 1.) an instance of that Entity is persisted or 2.) the given entity is reachable by another persisted entity.  Is this correct?

 

edit
delete
#6

Giving the following persistence unit definition:

<persistence-unit name="T824" >
  <provider>com.objectdb.jpa.Provider</provider>
  <class>T824$A</class>
  <exclude-unlisted-classes/>
  <properties>
   <property name="javax.persistence.jdbc.url" value="objectdb://localhost/db/test.tmp;drop" />
   <property name="javax.persistence.jdbc.user" value="admin" />
   <property name="javax.persistence.jdbc.password" value="admin" />
  </properties>
</persistence-unit>

This simple program:

import javax.persistence.Entity;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class T824 {

    public static void main(String[] args) {
        EntityManagerFactory emf =
            Persistence.createEntityManagerFactory("T824");
        System.out.println(emf.getMetamodel().getEntities());
        emf.close();
    }

    @Entity
    public static class A {
    }
}

produces the following output:

[Type T824$A]

So the metadata is available even though the database is still empty.

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.