I am using Hibernate Core 3.2.2 with Jboss Application Server 4.0.5GA. I managed to map my entities using myEntity.hbm.xml file for each. However, now I would like to use Hibernate Annotations to facilitate mapping especially when having attribute ovverrides in an embeddable class.
I have replaced the myEntity.hbm.xml files with hibernate.cfg.xml file which includes a list of mapping classes as follows. I have placed the config file in the root of my source code outside any package.
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:mysql://localhost/myDB
</property>
<property name="connection.username">guest</property>
<property name="connection.password">password</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<!-- mapping files -->
<mapping class="com.company.test.ejb.entity.TestEntity"/>
</session-factory>
</hibernate-configuration>
However when I run my application and arrive at the point of saving one of my entities, the following exception is thrown:
org.hibernate.MappingException: Unknown entity: com.company.test.ejb.entity.TestEntity
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:548)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1338)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:96)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at com.company.test.ejb.session.myTestApp.method1(TestThread.java:70)
So I'm assuming that during deployment the hibernate.cfg.xml is not being considered. Am I placing the file in the wrong place or do I have to add some configuration settings to Jboss?
Thanks
Gail
|