I was trying (still am, actually) to use Hibernate with JPA annotations for persisting simple POJOs to the db.
The complexity level is very similar to the Hello World tutorial.
So off I went and generated mapping annotations, persistence.xml file and a main class to handle the transactions.
All of this to fail on the first line of code:
EntityManagerFactory entityManagerFactory = Persistence
.createEntityManagerFactory("loggingLevels");
The failure is due to the fact that org.hibernate.ejb.Ejb3Configuration is picking up the wrong persistence.xml file for analyzing (from the activemq jar file, which is also on the class path). Since the persistence unit name noted in the main class does not appear in the other file - it just throws an error.
My persistence.xml is located next to my compiled classes under META_INF, just as required.
My question is - other than removing activemq jar file from the classpath - how can I make sure the correct persistence.xml file is being analized? (oh, yeah, and I've tried putting the META_INF on the top of the list of "order and export" in ecliipse and it did not make any difference.)
A few environment details (before the blob of the debug messages):
Hibernate 3.2
Hibernate Annotations 3.3.1
Hibernate Entity Manager 3.3.2
IDE - eclipse 3.3.2
activemq 5.1
VM - Java 1.6_0_06
OS - Windows XP 64bits
hardware - Dell, Intel core 2 quad cpu, 2.66GH, 3.93 GB of RAM
Here is the output to the console (after logging level was set to ALL):
0 [main] INFO org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.3.1.GA
0 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.2.5
15 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
15 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : cglib
15 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
78 [main] INFO org.hibernate.ejb.Version - Hibernate EntityManager 3.3.2.GA
94 [main] DEBUG org.hibernate.ejb.Ejb3Configuration - Look up for persistence unit: loggingLevels
94 [main] DEBUG org.hibernate.ejb.Ejb3Configuration - Analysing persistence.xml: jar:file:/C:/Documents%20and%20Settings/goren/My%20Documents/eclipse/workspace/common-libs/lib/active-mq/activemq-all-5.1.0.jar!/META-INF/persistence.xml
359 [main] DEBUG org.hibernate.ejb.packaging.PersistenceXmlLoader - Persistent Unit name from persistence.xml: activemq
359 [main] DEBUG org.hibernate.ejb.Ejb3Configuration - PersistenceMetadata [
name: activemq
jtaDataSource: null
nonJtaDataSource: null
transactionType: RESOURCE_LOCAL
provider: org.apache.openjpa.persistence.PersistenceProviderImpl
classes[
org.apache.activemq.store.jpa.model.StoredMessage org.apache.activemq.store.jpa.model.StoredSubscription org.apache.activemq.store.jpa.model.StoredMessageReference ]
packages[
]
mappingFiles[
]
jarFiles[
]
hbmfiles: 0
properties[
]]
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named loggingLevels
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
at nnl.util.logging.upload.UploadDataIntoLoggingTables.main(UploadDataIntoLoggingTables.java:37)
|