These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Need help with Hibernate
PostPosted: Thu Oct 02, 2008 11:12 am 
Newbie

Joined: Thu Oct 02, 2008 10:43 am
Posts: 11
I am getting this error when integrating Hibernate with Spring

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.hibernate.MappingException: invalid mapping


This is my applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">



<beans>

<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property>
<property name="url"><value>jdbc:mysql://localhost:3306/rml</value></property>
<property name="username"><value>mm</value></property>
<property name="password"><value>mm</value></property>

</bean>

<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref bean="myDataSource"/></property>
<property name="mappingResources">
<list>
<value>/com/rml/user.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
</value>
</property>
</bean>

<bean id="userdao" class="com.rml.UserDAO">
<property name="sessionFactory"><ref bean="mySessionFactory"/></property>

</bean>

</beans>


In the Spring I used as

<bean id="userController" class="com.rml.UserController">
<property name="userdao"><ref bean="userdao"/></property>

</bean>


Please help me How to solve this error


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2008 11:21 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
mahest2001,

Your problem seems to be in the mapping file (or whatever you are using for mapping classes to tables), not in the application.xml

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject: Re: Need help with Hibernate
PostPosted: Thu Oct 02, 2008 12:27 pm 
Newbie

Joined: Thu Oct 02, 2008 10:43 am
Posts: 11
I used one mapping file user.hbm.xml is

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.rml.UserBean" table="User">


<property name="firstName" column="first_name"/>
<property name="lastName" column="last_name"/>
<property name="password" column="password"/>



</class>

</hibernate-mapping>


I have created user table in mysql

Please help it


mahest2001 wrote:
I am getting this error when integrating Hibernate with Spring

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.hibernate.MappingException: invalid mapping


This is my applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">



<beans>

<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property>
<property name="url"><value>jdbc:mysql://localhost:3306/rml</value></property>
<property name="username"><value>mm</value></property>
<property name="password"><value>mm</value></property>

</bean>

<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref bean="myDataSource"/></property>
<property name="mappingResources">
<list>
<value>/com/rml/user.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
</value>
</property>
</bean>

<bean id="userdao" class="com.rml.UserDAO">
<property name="sessionFactory"><ref bean="mySessionFactory"/></property>

</bean>

</beans>


In the Spring I used as

<bean id="userController" class="com.rml.UserController">
<property name="userdao"><ref bean="userdao"/></property>

</bean>


Please help me How to solve this error


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2008 12:31 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Your mapping lacks an id, which is mandatory.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 03, 2008 2:11 pm 
Newbie

Joined: Thu Oct 02, 2008 10:43 am
Posts: 11
Thanks for your help. It is working now


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.