-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: JPA Annotated entity not found in 3rd+ jar MappingException
PostPosted: Fri Jul 27, 2007 1:14 pm 
Newbie

Joined: Fri Jul 27, 2007 12:33 pm
Posts: 1
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 27, 2007 3:40 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
explicitly list your external entities, (or use the <jar-file>), but do not duplicate persistence.xml, it should be set once and only once per persistence unit definition

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.