Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

org hibernate InvalidMappingException : Could not parse mapping document from invalid

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been trying to resolve the above error for the last one day.
But i could not.
The below exception is occuring when iam trying to access Spring-Hibernate XML Configuration files from the controller code.

Below i copied down the
1) Exception Details
2) Spring-hibernate.xml file
3) sample.hbm.xml
4) snippet of COntroller Code.

Can anyone please guide me on how to resolve this issue.
Below are the details of the Exception.

Exception Details
~~~~~~~~~~~~
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'sessionFactory' defined in class path resource [hibernate/spring-hibernate.xml]: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Could not parse mapping document from invalid mapping
org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1174)
org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:425)




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


<beans>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
<property name="driverClassName"> <value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost/sample</value>
</property>
<property name="username"><value>rama</value></property>
<property name="password"><value>rama</value></property>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<value>sqlmap/sample.hbm.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQ LDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
</props>
</property>


</bean>

<bean id="MyBean2Dao" class="com.prospring.dao.HibernateMyBean2DAO">
<property name="sessionFactory"> <ref local="sessionFactory"/> </property>
</bean>
</beans>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


sqlmap====>sample.hbm.xml is as below
~~~~~~~~~~~~~~~~~~~~~~~~~~
<?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 auto-import="true" default-lazy="false">
<class name="com.prospring.controller.MyBean2" table="test">
<property name="a1" column="a1" type="java.lang.String"/>
<property name="a2" column="a2" type="java.lang.String"/>
</class>
</hibernate-mapping>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Snippet of Controller COde is as below
~~~~~~~~~~~~~~~~~~
ApplicationContext context = new ClassPathXmlApplicationContext("/hibernate/spring-hibernate.xml");
MyBean2DAO m2 = (MyBean2DAO)context.getBean("MyBean2Dao");



I rechecked the xml configuration file many times still i could not able to find out the error. Can anyone please guide me on how to resolve this issue?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your sample.hbm.xml doesn't define an ID. Make sure you properly map the id of the object to the primary key of your entity.
 
ramaa Vadakattuu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much Paul.Error got resolved.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic