Hi,
I have an issue with the EntityManager. My persistance XML looks like:
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.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_2_0.xsd"> <persistence-unit name="xPU" transaction-type="RESOURCE_LOCAL"> <provider>com.objectdb.jpa.Provider</provider> <properties> <property name="javax.persistence.jdbc.url" value="objectdb/db/x.odb"/> <property name="javax.persistence.jdbc.user" value="admin"/> <property name="javax.persistence.jdbc.password" value="admin"/> </properties> </persistence-unit> </persistence>
Now in our project we use spring to start everything. If I do:
System.out.println("EntityManager Name: " + em.getClass().getName());
The result is: com.objectdb.jpa.EMImpl
However if I create a basic test project, NO spring involved. Same
persistance xml in my META-INF, startup using:
emf = Persistence.createEntityManagerFactory("xPU"); em = emf.createEntityManager();
and run the same command, I get: com.objectdb.jdo.PMImpl
Whats going on here? Is the entityManager not controlled by the
persistance.xml or is something in the spring is doing something I
don't understand? Or have I missed something?
The reason I ask this is, I have an entity class that contains another
entity, and that entity holds a Map. If I retrieve the initial object
using "select t from someobject t" then everything comes back
correctly. However if I use em.find(SomeObject.class, id) the map is
NOT populated. I created a simple test to demonstrate this, however in
the simple test it all works fine, and the only difference I can find
is the entityManager thats being used. BUT I can't seem to force the
unit test to use the JPA entity manager which I believe it should be
using.
Thanks