views:

736

answers:

1

I'm building a desktop application using hibernate 3.5 & JPA 2.0.

I have 2 jars,

the lib, which defines every entity and DAO, packages looks like this :

org.my.package.models
org.my.package.models.dao
org.my.package.models.utils

In org.my.package.utils I defined my hibernate utility class for getting EM & EMF instances, which means the lib is bound to a Persistence Unit name but that's not a problem for now (anyway you can recommend me a better way to manage that)

the second jar is built as follow:

org.my.package.app

META-INF is defined on the root of the project which means in my jar I can find this directories directly in the root:

META-INF/
META-INF/persistence.xml
org/
org/my/
...
org/my/package/app/Main.class

When I run the app, hibernate doesn't managed to find persistence.xml it throws an exception something like "package or class for PersistenceUnitName not found".

SLF4J: The requested version 1.5.11 by your slf4j binding is not compatible with [1.5.5, 1.5.6, 1.5.7, 1.5.8]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
3 [main] INFO org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.5.0-Final
25 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.5.0-Final
28 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
33 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
41 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
153 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
160 [main] INFO org.hibernate.ejb.Version - Hibernate EntityManager 3.5.0-Final
Exception in thread "main" java.lang.ExceptionInInitializerError
        at Main.main(Main.java:171)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: PMMPU] class or package not found
        at org.hibernate.ejb.Ejb3Configuration.addNamedAnnotatedClasses(Ejb3Configuration.java:1316)
        at org.hibernate.ejb.Ejb3Configuration.addClassesToSessionFactory(Ejb3Configuration.java:1094)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:981)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:275)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:359)
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:55)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
        at dil.tal.polymarmots.utils.HibernateUtil.getEmf(HibernateUtil.java:45)
        at dil.tal.polymarmots.utils.HibernateUtil.getEm(HibernateUtil.java:54)
        at dil.tal.polymarmots.utils.HibernateUtil.getMotDAOImpl(HibernateUtil.java:115)
        at dil.tal.polymarmots.models.Mot.<clinit>(Mot.java:30)
        ... 1 more
Caused by: java.lang.ClassNotFoundException: model.Extrait
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:247)
        at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:170)
        at org.hibernate.ejb.Ejb3Configuration.classForName(Ejb3Configuration.java:1232)
        at org.hibernate.ejb.Ejb3Configuration.addNamedAnnotatedClasses(Ejb3Configuration.java:1304)
        ... 11 more

I googled a bit about the problem but I can't get the source code organisation right.

Any help ?

+2  A: 

The class or package not found message is self-explaining: a class or a package is not found - not the persistence.xml - as suggested by the cause of the exception:

Caused by: java.lang.ClassNotFoundException: model.Extrait

The model.Extrait entity doesn't reflect the packaging you're showing but it is very likely declared in your persistence.xml (that you're not showing) but not present on the class path.

Pascal Thivent
shame on me this is really stupid.
phmr
This error helped me to understand that I didn't understand Java Exceptions output...
phmr
@phmr We all learn from mistakes :) Some call succession of mistakes "experience".
Pascal Thivent