-->
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: Loading of Persistent Entities in Hibernate JPA
PostPosted: Tue Nov 27, 2007 12:15 am 
Newbie

Joined: Mon Nov 26, 2007 11:51 pm
Posts: 2
1. I am posting this after few hours of scanning through documentation.

2. The problem is Hibernate JPA complains during bootstrap (Persistence.createEntityManagerFactory()) about loading persistent entities by name.

3. Typical log and error stack trace can be found at the end of this message.

The error appears as
Exception in thread "main" java.lang.NoClassDefFoundError: classes/domain/Actor (wrong name: domain/Actor)

However the log shows
19:45:13,078 DEBUG JarVisitor:258 - Filtering: classes.domain.Actor
19:45:13,078 DEBUG JarVisitor:309 - Java element filter matched for classes.domain.Actor

4. I have tried listing the entities in <class> tag in META-INF/persistence.xml or omiiting them altogether. But both cases the same error appears.

5. One of the workarounds is to configure <exclude-unlisted-classes>true</>

6. Any insight on entity class loading and recommended way to resolve the reported error will be useful.

7. Log and stack trace without <exclude-unlisted-classes>

19:45:12,328 INFO Version:15 - Hibernate Annotations 3.3.0.GA
19:45:12,343 INFO Environment:514 - Hibernate 3.2.5
19:45:12,359 INFO Environment:532 - loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.hsqldb.jdbcDriver, hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.max_fetch_depth=1, hibernate.dialect=org.hibernate.dialect.HSQLDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.format_sql=true, hibernate.query.substitutions=yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=sa, hibernate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:hsqldb:./build/db/hsqldb/hibernate, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.password=****, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=1}
19:45:12,359 INFO Environment:563 - using java.io streams to persist binary types
19:45:12,359 INFO Environment:681 - Bytecode provider name : cglib
19:45:12,359 INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
19:45:12,437 INFO Version:15 - Hibernate EntityManager 3.3.1.GA
19:45:12,453 DEBUG Ejb3Configuration:202 - Look up for persistence unit: eBook
19:45:12,453 DEBUG Ejb3Configuration:214 - Analyse of persistence.xml: file:/C:/workspace/eBook/META-INF/persistence.xml
19:45:12,859 DEBUG DTDEntityResolver:38 - trying to resolve system-id [http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd]
19:45:12,859 DEBUG EJB3DTDEntityResolver:49 - recognized EJB3 ORM namespace; attempting to resolve on classpath under org/hibernate/ejb
19:45:12,875 DEBUG EJB3DTDEntityResolver:58 - located [http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd] in classpath
19:45:13,000 DEBUG PersistenceXmlLoader:156 - Persistent Unit name from persistence.xml: eBook
19:45:13,000 DEBUG Ejb3Configuration:221 - PersistenceMetadata [
name: eBook
jtaDataSource: null
nonJtaDataSource: null
transactionType: RESOURCE_LOCAL
provider: null
classes[
]
packages[
]
mappingFiles[
]
jarFiles[
]
hbmfiles: 0
properties[
hibernate.cglib.use_reflection_optimizer: true
]]
19:45:13,000 DEBUG JarVisitor:91 - JAR URL from URL Entry: file:/C:/workspace/eBook/META-INF/persistence.xml >> file:/C:/workspace/eBook
19:45:13,000 DEBUG Ejb3Configuration:553 - Detect class: true; detect hbm: true
19:45:13,015 DEBUG JarVisitor:218 - Searching mapped entities in jar/par: file:/C:/workspace/eBook
19:45:13,015 DEBUG JarVisitor:258 - Filtering: classes.client.CustomerSession
19:45:13,046 DEBUG JarVisitor:258 - Filtering: classes.client.SessionStatistics
19:45:13,062 DEBUG JarVisitor:258 - Filtering: classes.client.Shop
19:45:13,062 DEBUG JarVisitor:258 - Filtering: classes.domain.AbstractArtist
19:45:13,078 DEBUG JarVisitor:309 - Java element filter matched for classes.domain.AbstractArtist
19:45:13,078 DEBUG JarVisitor:258 - Filtering: classes.domain.Actor
19:45:13,078 DEBUG JarVisitor:309 - Java element filter matched for classes.domain.Actor
19:45:13,078 DEBUG JarVisitor:258 - Filtering: classes.domain.Artist
19:45:13,078 DEBUG JarVisitor:258 - Filtering: classes.domain.Author
19:45:13,078 DEBUG JarVisitor:309 - Java element filter matched for classes.domain.Author
19:45:13,078 DEBUG JarVisitor:258 - Filtering: classes.domain.Book
19:45:13,078 DEBUG JarVisitor:309 - Java element filter matched for classes.domain.Book
19:45:13,078 DEBUG JarVisitor:258 - Filtering: classes.domain.CD
19:45:13,078 DEBUG JarVisitor:309 - Java element filter matched for classes.domain.CD
19:45:13,078 DEBUG JarVisitor:258 - Filtering: classes.domain.Customer
19:45:13,078 DEBUG JarVisitor:309 - Java element filter matched for classes.domain.Customer
19:45:13,093 DEBUG JarVisitor:258 - Filtering: classes.domain.DVD
19:45:13,093 DEBUG JarVisitor:309 - Java element filter matched for classes.domain.DVD
19:45:13,093 DEBUG JarVisitor:258 - Filtering: classes.domain.Inventory
19:45:13,093 DEBUG JarVisitor:309 - Java element filter matched for classes.domain.Inventory
19:45:13,093 DEBUG JarVisitor:258 - Filtering: classes.domain.Item
19:45:13,093 DEBUG JarVisitor:309 - Java element filter matched for classes.domain.Item
19:45:13,093 DEBUG JarVisitor:258 - Filtering: classes.domain.LineItem$CompoundId
19:45:13,093 DEBUG JarVisitor:258 - Filtering: classes.domain.LineItem
19:45:13,093 DEBUG JarVisitor:309 - Java element filter matched for classes.domain.LineItem
19:45:13,093 DEBUG JarVisitor:258 - Filtering: classes.domain.Price
19:45:13,093 DEBUG JarVisitor:309 - Java element filter matched for classes.domain.Price
19:45:13,093 DEBUG JarVisitor:258 - Filtering: classes.domain.PurchaseOrder
19:45:13,109 DEBUG JarVisitor:309 - Java element filter matched for classes.domain.PurchaseOrder
19:45:13,109 DEBUG JarVisitor:258 - Filtering: classes.domain.Singer
19:45:13,109 DEBUG JarVisitor:309 - Java element filter matched for classes.domain.Singer
19:45:13,109 DEBUG JarVisitor:258 - Filtering: classes.service.AuditService$Default
19:45:13,109 DEBUG JarVisitor:258 - Filtering: classes.service.AuditService
19:45:13,109 DEBUG JarVisitor:258 - Filtering: classes.service.BrowserService$Default
19:45:13,109 DEBUG JarVisitor:258 - Filtering: classes.service.BrowserService
19:45:13,109 DEBUG JarVisitor:258 - Filtering: classes.service.CustomerService$Default
19:45:13,109 DEBUG JarVisitor:258 - Filtering: classes.service.CustomerService
19:45:13,109 DEBUG JarVisitor:258 - Filtering: classes.service.DataLoadingService
19:45:13,109 DEBUG JarVisitor:258 - Filtering: classes.service.ItemFactory
19:45:13,125 DEBUG JarVisitor:258 - Filtering: classes.service.OrderingService$Default
19:45:13,125 DEBUG JarVisitor:258 - Filtering: classes.service.OrderingService
19:45:13,125 DEBUG JarVisitor:258 - Filtering: classes.service.PersistenceService
19:45:13,125 DEBUG JarVisitor:258 - Filtering: classes.service.PricingService$Default
19:45:13,125 DEBUG JarVisitor:258 - Filtering: classes.service.PricingService
19:45:13,140 DEBUG JarVisitor:258 - Filtering: classes.service.ServiceFactory
19:45:13,140 DEBUG JarVisitor:258 - Filtering: classes.service.ShoppingCart
19:45:13,140 DEBUG JarVisitor:258 - Filtering: classes.util.Configuration
19:45:13,140 DEBUG JarVisitor:258 - Filtering: classes.util.NormalDistribution
19:45:13,140 DEBUG JarVisitor:258 - Filtering: classes.util.RandomSelector$Distribution
19:45:13,140 DEBUG JarVisitor:258 - Filtering: classes.util.RandomSelector
19:45:13,140 DEBUG JarVisitor:258 - Filtering: classes.util.Statistics
19:45:13,140 DEBUG JarVisitor:258 - Filtering: classes.util.UniformDistribution
19:45:13,171 DEBUG Ejb3Configuration:553 - Detect class: true; detect hbm: true
19:45:13,171 DEBUG Ejb3Configuration:154 - Creating Factory: eBook
Exception in thread "main" java.lang.NoClassDefFoundError: classes/domain/Actor (wrong name: domain/Actor)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:112)
at org.hibernate.ejb.Ejb3Configuration.classForName(Ejb3Configuration.java:1041)
at org.hibernate.ejb.Ejb3Configuration.addNamedAnnotatedClasses(Ejb3Configuration.java:1113)
at org.hibernate.ejb.Ejb3Configuration.addClassesToSessionFactory(Ejb3Configuration.java:905)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:792)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:186)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:246)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at service.PersistenceService.<clinit>(Unknown Source)
at service.ServiceFactory.getAuditService(Unknown Source)
at client.Shop.main(Unknown Source)


Top
 Profile  
 
 Post subject: Loading of Persistent Entities in Hibernate JPA
PostPosted: Mon Feb 25, 2008 12:17 pm 
Newbie

Joined: Thu Mar 11, 2004 4:00 pm
Posts: 5
Location: Canada
Hi,

I have the same problem and I understand what happens but the easiest workaround I have is the one you mentioned : configure <exclude-unlisted-classes>true</>.

The problem happens when in Eclipse you define one or more source directories and a different default output folder.

For example, if you have a project with the following structure :
MyProject
- src
-- com
--- test
---- MyEntity.java
- bin
-- com
--- test
---- MyEntity.class

the ExplodedJarVisitor visits all the nodes and when it arrives at MyEntity.class, the path is bin.com.test.MyEntity.class which is the wrong package for the class.
Probably, if possible, I guess it should use the real .class package because it uses the path from the current entry of the exploded jar.

I haven't tested it but the other workaroud should be to have your package structure start from the root of the project.

Hope it helps.

_________________
Daniel


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.