Hibernate version: 3.1 beta3
EntityManager version: 3.1 beta3
Section 2.2 of the entity manager docs suggests that all classes in a persistence archive that are marked with @Entity will be added to the persistence unit configuration. I have bundled my @Entity objects along with META-INF/persistence.xml into a persistence archive file (.par) and put that archive on my classpath. My persistence.xml looks something like this...
Code:
<entity-manager>
<name>mymanager</name>
<properties>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost/mydb"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.password" value="secret"/>
<property name="hibernate.connection.username" value="me"/>
</properties>
</entity-manager>
I have found that if I don't have class elements in my persistence.xml file then when I try to persist an object I get an exception like this...
Code:
[java] java.lang.IllegalArgumentException: Unknown entity: com.foo.Bar
[java] at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:133)
The archive does contain my persistent classes that have been marked with @Entity. If I had a class element to my persistence.xml like this things seem to work fine...
Code:
<entity-manager>
<name>mymanager</name>
<class>com.foo.Bar</class>
<properties>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost/mydb"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.password" value="secret"/>
<property name="hibernate.connection.username" value="me"/>
</properties>
</entity-manager>
I have read Chapter 6 of the current draft of the JSR220 spec. and it still is not clear to me how this is supposed to work in a J2SE environment.
Do the classes need to be specified in class elements in my persistence.xml file or should the environment find that they are in the persistent archive and have been marked with @Entity? I am specifically interested in the behavior in a J2SE environment, not in a J2EE container.
Thanks for your time.
Jeff