I am a newbie to Hibernate myself, and I have been running some tests after reading half of "Hibernate in Action" and stumbled onto a problem that I have, so far, been unable to locate let alone solve.
The problem resides in the fact that I am getting the error shown in the trace below.
To solve this problem I tackled both the documentation in this site and the web, and while I was able to locate a couple cases that were facing the same problem I am, their proposed solution does not seem to work for me. This solution mentions that the cause of the problem was that there was an either absent entity mapping xml file (<entity>.hbm.xml file that is) or that the file was present but not mapped in the cfg.xml Hibernate configuration file.
My particular project is working with Spring Framework on top, and thus I dont have a configuration file as such, rather, in the applicationContext.xml file, there are sections to include all parts of the Hibernate configuration file, it is there that I placed the locations of the mapping files as they would otherwise be put in a standard configuration file, the relevan excerpt from the file I post below:
Code:
<bean id = "pruebasWaldoSessionFactory" class = "org.springframework.orm.hibernate.LocalSessionFactoryBean">
<!--Aqui es donde se esta ligando hacia el mapeo de los recursos (tablas en la base de datos)-->
<property name = "mappingResources">
<list>
<!--Las rutas hacia los archivos .hbm.xml son relativos a la raiz del proyecto.-->
<value>com/pruebaswaldo/model/Usuario.hbm.xml</value>
<value>com/pruebaswaldo/model/Nicknames.hbm.xml</value>
</list>
</property>
<property name = "hibernateProperties">
<!--Cabe mencionar que las propiedades que se definen en esta lista no incluyen los pertinentes a la conexion a la base de datos, porque estos se defi_
nen arriba en el bean de datasource-->
<props>
<prop key = "hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</prop>
<prop key = "hibernate.show_sql">true</prop>
<prop key = "hibernate.use_outer_join">true</prop>
<prop key = "hibernate.transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactory</prop>
</props>
</property>
<property name = "dataSource">
<ref bean = "dataSource"/>
</property>
</bean>
Basically what the application works on are two different tables
Code:
usuario
and
Code:
nicknames
which are related by the field
Code:
user_id
. I am trying to insert a new entry into the
Code:
nicknames
and I get the mentioned exception in return :/ I would appreciate whatever help you can provide as to locating the cause of this problem. I include the rest of the requested information.
Hibernate version: 2.1
Mapping documents:The nickname mapping document:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
>
<class
name="com.pruebaswaldo.model.Nicknames"
table="nicknames"
dynamic-update="true"
dynamic-insert="true"
select-before-update="false"
optimistic-lock="version"
mutable="true"
>
<id
name="id"
column="nick_id"
type="int"
>
<generator class="identity">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Nicknames.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<property
name="activation"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="nick_activationDate"
not-null="true"
/>
<property
name="deActivation"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="nick_deactivationDate"
/>
<property
name="nickname"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="nick_nickname"
not-null="true"
/>
<many-to-one
name="userId"
class="com.pruebaswaldo.model.Usuario"
cascade="all"
outer-join="auto"
update="true"
insert="true"
access="property"
column="nick_user_id"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Nicknames.xml
containing the additional properties and place it in your merge dir.
-->
</class>
<query name="findUserNicknames"><![CDATA[
FROM Nicknames AS nicks WHERE Usuario.id = ?
]]></query>
<query name="findRegisteredNicknames"><![CDATA[
FROM Nicknames AS nicks
]]></query>
<query name="findNicknamesByDate"><![CDATA[
FROM Nicknames AS nicks WHERE nicks.activation = ?
]]></query>
<query name="findDeactivatedNicknames"><![CDATA[
FROM Nicknames AS nicks WHERE nicks.deActivation != NULL
]]></query>
<query name="findByDeactivationDate"><![CDATA[
FROM Nicknames AS nicks WHERE nicks.deActivation = ?
]]></query>
</hibernate-mapping>
the Usuario mapping document:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
>
<class
name="com.pruebaswaldo.model.Usuario"
table="usuario"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
>
<id
name="id"
column="user_id"
type="int"
>
<generator class="identity">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Usuario.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="user_name"
/>
<property
name="lastName"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="user_lastName"
/>
<set
name="nicknames"
lazy="true"
inverse="true"
cascade="all"
sort="unsorted"
>
<key
column="user_id"
>
</key>
<one-to-many
class="com.pruebaswaldo.model.Nicknames"
/>
</set>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Usuario.xml
containing the additional properties and place it in your merge dir.
-->
</class>
<query name="findUsuarioId"><![CDATA[
FROM Usuario AS u WHERE u.id = ?
]]></query>
<query name="findUsuarios"><![CDATA[
]]></query>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Nicknames nick = new Nicknames();
nick.setUserId(1);
nick.setNickname("Kurokitsune");
nick.setActivation(new GregorianCalendar().getTime());
getHibernateTemplate().save(nick);
Please remember that with Spring support my handling of the transaction is a tad different than with Hibernate alone, however this is what would usually be placed in the session space.
Full stack trace of any exception that occurs:
org.springframework.orm.hibernate.HibernateSystemException: No persister for: java.lang.Integer; nested exception is net.sf.hibernate.MappingException: No persister for: java.lang.Integer
net.sf.hibernate.MappingException: No persister for: java.lang.Integer
at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:347)
at net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2687)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2694)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1382)
at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:114)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:436)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:503)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:890)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:857)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:775)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
at org.springframework.orm.hibernate.HibernateTemplate$9.doInHibernate(HibernateTemplate.java:555)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:363)
at org.springframework.orm.hibernate.HibernateTemplate.save(HibernateTemplate.java:552)
at com.pruebaswaldo.sdo.impl.HibernatePruebasWaldoServiceData.store(HibernatePruebasWaldoServiceData.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:335)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
at $Proxy0.store(Unknown Source)
at com.pruebaswaldo.PruebasWaldoTest.addNickname(PruebasWaldoTest.java:104)
at com.pruebaswaldo.PruebasWaldoTest.testAddNickname(PruebasWaldoTest.java:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Name and version of the database you are using:
MySQL 4.1
The generated SQL (show_sql=true):
no SQL is shown (and I personally think that is weird O.o but being a noob I'm not sure if it is normal on save operations that crash before they occur)
I apologize for the rather longish post, but the guidelines did say to provide as much information as possible :p
I really hope someone out there can help... I am certain that it is a mapping mistake, and a noob and stupid one at that, but I really cant find the reason!
Also, I hesitated to post this on the Spring forums since the exception thrown by JUnit is in the end a Hibernate one, but if you believe I should take my questions there, please tell me so!
Thanks in advance ppl