aspose file tools*
The moose likes Object Relational Mapping and the fly likes org hibernate InvalidMappingException : Could not parse mapping document from invalid Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "org hibernate InvalidMappingException : Could not parse mapping document from invalid" Watch "org hibernate InvalidMappingException : Could not parse mapping document from invalid" New topic
Author

org hibernate InvalidMappingException : Could not parse mapping document from invalid

ramaa Vadakattuu
Greenhorn

Joined: Oct 12, 2007
Posts: 7
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?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
ramaa Vadakattuu
Greenhorn

Joined: Oct 12, 2007
Posts: 7
Thank you so much Paul.Error got resolved.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: org hibernate InvalidMappingException : Could not parse mapping document from invalid