Hi, everyone.
I am converting from TOPLink Essentials to Hibernate 3.4, both using JPA, all inside of Spring 2.5, inside of Tomcat 6, running against MySQL 5.
My application currently functions with TOPLink. To convert to Hibernate, I updated the files below.
I'm not using any annotations, only the orm.xml for mapping. However, I get the exception below, seeming to indicate that Hibernate wants an ID defined for that first entity.
I'm using exclude-unlisted-classes, which I didn't seem to need with TOPLink, but I understand I need with Hibernate. The Spring docs say to use it like I do below, but I've also tried putting a true in there, but the same thing happens.
I'm not sure if my persistence.xml is not being picked up (it's in a META-INF in one of my jars), but it's in the same place as it was for TOPLink (same with the orm.xml which Hibernate seems to find).
I've searched around and found the same error but not the same context.
Any help is greatly appreciated.
Hibernate version: 3.4.0
Mapping documents:
persistence.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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/persistence_1_0.xsd" version="1.0">
<persistence-unit name="myDB" transaction-type="RESOURCE_LOCAL">
<mapping-file>META-INF/orm.xml</mapping-file>
<exclude-unlisted-classes />
</persistence-unit>
</persistence>
applicationContext-jpa.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Application context definition for PetClinic on JPA.
-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="loadTimeWeaver" class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/mydb"/>
<property name="username" value="myuser"/>
<property name="password" value="mypass"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" p:dataSource-ref="dataSource">
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="false" />
<property name="generateDdl" value="true" />
</bean>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory"/>
<tx:annotation-driven transaction-manager="transactionManager" mode="proxy"/>
<context:annotation-config/>
</beans>
Code between sessionFactory.openSession() and session.close():Full stack trace of any exception that occurs:Code:
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: my.coolness.domain.search.Searchable
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:672)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:546)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:291)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1226)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:173)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:425)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:131)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:227)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:273)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1367)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1333)
... 107 more
Name and version of the database you are using: MySQL 5.0
The generated SQL (show_sql=true):Debug level Hibernate log excerpt:Code:
[2009-02-27 12:25:47,255] INFO org.hibernate.cfg.annotations.Version Hibernate Annotations 3.4.0.GA
[2009-02-27 12:25:47,268] INFO org.hibernate.cfg.Environment Hibernate 3.3.0.SP1
[2009-02-27 12:25:47,272] INFO org.hibernate.cfg.Environment hibernate.properties not found
[2009-02-27 12:25:47,275] INFO org.hibernate.cfg.Environment Bytecode provider name : javassist
[2009-02-27 12:25:47,280] INFO org.hibernate.cfg.Environment using JDK 1.4 java.sql.Timestamp handling
[2009-02-27 12:25:47,359] INFO org.hibernate.annotations.common.Version Hibernate Commons Annotations 3.1.0.GA
[2009-02-27 12:25:47,363] INFO org.hibernate.ejb.Version Hibernate EntityManager 3.4.0.GA
[2009-02-27 12:25:47,407] DEBUG org.hibernate.ejb.Ejb3Configuration Processing PersistenceUnitInfo [
name: myDB
persistence provider classname: null
classloader: org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader
WebappClassLoader
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@4ac4aad3
Temporary classloader: WebappClassLoader
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@4ac4aad3
excludeUnlistedClasses: true
JTA datasource: null
Non JTA datasource: org.springframework.jdbc.datasource.DriverManagerDataSource@29c5f7df
Transaction type: RESOURCE_LOCAL
PU root URL: file:/Users/Me/Documents/Projects/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/WebProject/WEB-INF/lib/WebProjectIntegration.jar
Jar files URLs []
Managed classes names []
Mapping files names [
META-INF/orm.xml]
Properties []
[2009-02-27 12:25:47,407] DEBUG org.hibernate.ejb.Ejb3Configuration Detect class: true; detect hbm: true
[2009-02-27 12:25:47,421] DEBUG org.hibernate.ejb.packaging.AbstractJarVisitor Searching mapped entities in jar/par: file:/Users/Me/Documents/Projects/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/WebProject/WEB-INF/lib/WebProjectIntegration.jar
[2009-02-27 12:25:47,469] DEBUG org.hibernate.util.DTDEntityResolver trying to resolve system-id [file:///Users/Me/Eclipse/Eclipse.app/Contents/MacOS/orm_1_0.xsd]
[2009-02-27 12:25:47,469] DEBUG org.hibernate.cfg.EJB3DTDEntityResolver recognized EJB3 ORM namespace; attempting to resolve on classpath under org/hibernate/ejb
[2009-02-27 12:25:47,471] DEBUG org.hibernate.cfg.EJB3DTDEntityResolver located [file:///Users/Me/Eclipse/Eclipse.app/Contents/MacOS/orm_1_0.xsd] in classpath
[2009-02-27 12:25:47,878] INFO org.hibernate.cfg.Configuration Reading mappings from resource : META-INF/orm.xml
[2009-02-27 12:25:47,886] DEBUG org.hibernate.util.DTDEntityResolver trying to resolve system-id [file:///Users/Me/Eclipse/Eclipse.app/Contents/MacOS/orm_1_0.xsd]
[2009-02-27 12:25:47,886] DEBUG org.hibernate.cfg.EJB3DTDEntityResolver recognized EJB3 ORM namespace; attempting to resolve on classpath under org/hibernate/ejb
[2009-02-27 12:25:47,886] DEBUG org.hibernate.cfg.EJB3DTDEntityResolver located [file:///Users/Me/Eclipse/Eclipse.app/Contents/MacOS/orm_1_0.xsd] in classpath
[2009-02-27 12:25:48,014] DEBUG org.hibernate.cfg.annotations.reflection.XMLContext Adding XML overriding information for my.coolness.domain.search.Searchable
[2009-02-27 12:25:48,014] DEBUG org.hibernate.cfg.annotations.reflection.XMLContext Adding XML overriding information for listener: org.dom4j.tree.DefaultElement@767b299b [Element: <entity-listeners uri: http://java.sun.com/xml/ns/persistence/orm attributes: []/>]
[2009-02-27 12:25:48,014] DEBUG org.hibernate.cfg.annotations.reflection.XMLContext Adding XML overriding information for my.coolness.domain.user.User
[2009-02-27 12:25:48,014] DEBUG org.hibernate.cfg.annotations.reflection.XMLContext Adding XML overriding information for listener: null
// A lot more of the same ....
[2009-02-27 12:25:48,055] INFO org.hibernate.ejb.Ejb3Configuration [PersistenceUnit: myDB] META-INF/orm.xml found
[2009-02-27 12:25:48,056] DEBUG org.hibernate.cfg.AnnotationConfiguration Execute first pass mapping processing
[2009-02-27 12:25:48,465] DEBUG org.hibernate.cfg.AnnotationConfiguration Process hbm files
[2009-02-27 12:25:48,465] DEBUG org.hibernate.cfg.AnnotationConfiguration Process annotated classes
[2009-02-27 12:25:48,476] INFO org.hibernate.cfg.AnnotationBinder Binding entity from annotated class: my.coolness.domain.matching.MatchableEntity
[2009-02-27 12:25:48,545] DEBUG org.hibernate.cfg.annotations.EntityBinder Import with entity name MatchableEntity
[2009-02-27 12:25:48,548] INFO org.hibernate.cfg.annotations.EntityBinder Bind entity my.coolness.domain.matching.MatchableEntity on table MATCHABLE_ENTITY
[2009-02-27 12:25:48,554] DEBUG org.hibernate.cfg.AnnotationBinder Processing my.coolness.domain.matching.MatchableEntity property annotation
[2009-02-27 12:25:48,629] DEBUG org.hibernate.cfg.AnnotationBinder Processing my.coolness.domain.matching.MatchableEntity field annotation
[2009-02-27 12:25:48,773] ERROR org.springframework.web.context.ContextLoader Context initialization failed
// then that big exception