Similar to:
http://forum.hibernate.org/viewtopic.ph ... highlight=
SCENARIO:
Having a Hibernate EntityManager/Annotations related sope, and/or classpath implementation issue
with the folowing environ in a java SE 1.6 junit 3.8.1 testing scenario:
[Version] Hibernate Annotations 3.3.0.GA
[Version] Hibernate 3.2.4.sp1
[Environment] Bytecode provider name : cglib
[Environment] using JDK 1.4 java.sql.Timestamp handling
[Version] Hibernate EntityManager 3.3.1.GA
Have three class library jar files: call them JA, JB, and JC.
All three class library jars contain an annotated entity class: call them EA in JA, EB in JB, and EC in JC
All three class library jars also contain a copy of the following META-INF/persistence.xml file:
<?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/ ... ce_1_0.xsd">
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<property name="hibernate.ejb.cfgfile" value="/hibernate.cfg.xml"/>
</properties>
</persistence-unit>
</persistence>
with the root directory containing hibernate.cfg.xml file (connection url, uid, pwd omitted):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="java:/hibernate/HibernateFactory">
<property name="hbm2ddl.auto">create</property>
<property name="show_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
...
<property name="c3p0.min_size">3</property>
<property name="c3p0.max_size">5</property>
<property name="c3p0.timeout">300</property>
<property name="c3p0.max_statements">50</property>
<property name="c3p0.idle_test_period">3000</property>
<property name="generate_statistics">true</property>
</session-factory>
</hibernate-configuration>
REQUIREMENT:
Need controller class in JA to be able to use all three entities, EA in JA, EB in JB, and EC in JC and all three class libraries must remain separate.
CURRENT CAPABILITY:
a controller class in JB can find and use EB in JB, as well as, EC in JC when JB is tested alone with JC as the first class library in JB's run-time classpath.
also, controller in JA can use EC in JC when JC is the first class library in JA's run-time classpath.
PROBLEM:
controller in JA cannot use EC in JC when JB is placed before JC in JA's run-time classpath and causes the following error to be thrown:
Caused by: org.hibernate.MappingException: Unknown entity: EC
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:550)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1338)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:512)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:70)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
QUESTION(S):
1) can the requirement described above be met in the current versions of Hibernate, et. al. using annotations/JPA?
2) If so, any best practice for meeting such a requirement? ie.: <mapping class=... entries in persistence.xml or hibernate.cfg.xml?
3) Has any one else experienced this problem? Work around(s)?
Thank you, in advance, for any and all help.
Mark