Je construis une application de bureau en utilisant Hibernate 3.5 & JPA 2.0.JPA 2.0, hibernate 3.5, jars et l'emplacement persistence.xml
J'ai 2 pots,
la lib, qui définit toutes les entités et DAO, les paquets ressemble à ceci:
org.my.package.models
org.my.package.models.dao
org.my.package.models.utils
Dans org.my.package.utils je définis ma mise en veille prolongée classe utilitaire pour obtenir EM & instances de champs électromagnétiques, ce qui signifie que la lib est lié à un nom de la persistance, mais ce n'est pas un problème pour l'instant (de toute façon, vous pouvez me recommander une meilleure façon de gérer cela)
le deuxième pot est construit comme suit:
org.my.package.app
META-INF est défini à la racine du projet ce qui signifie que dans mon pot je peux trouver ce répertoires directement à la racine:
META-INF/
META-INF/persistence.xml
org/
org/my/
...
org/my/package/app/Main.class
Quand je exécutez l'application, hibernate ne parvient pas à trouver persistence.xml il lève une exception quelque chose comme "package ou une classe pour 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
Je googlé un peu the problem mais je ne peux pas obtenir l'organisation du code de bonne source.
Une aide?
Etes-vous sûr que le message signifie que le fichier n'est pas trouvé, plutôt qu'un problème dans le fichier? – Bozho
Post le ** exact ** exception (et trace) et votre persistence.xml –
http://techblog.bozho.net/?p=155 – Bozho