0

Since I am new to Hibernate and mapping. I am unable to find the exact issue for this cause. I will update the question heading when I find out what exactly is the issue. I am getting the following error when running the spring project. The hbm.xml are generated from the JBoss Hibernate Tools. (I will)

Stack Trace is given below

    Mar 10, 2014 4:28:05 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
    INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@a4c4a0d: display name [org.springframework.context.support.ClassPathXmlApplicationContext@a4c4a0d]; startup date [Mon Mar 10 16:28:05 IST 2014]; root of context hierarchy
    Mar 10, 2014 4:28:05 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [config/beanLocations.xml]
    Mar 10, 2014 4:28:05 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [database/dataSource.xml]
    Mar 10, 2014 4:28:05 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [database/hibernate.xml]
    Mar 10, 2014 4:28:21 PM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
    INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@a4c4a0d]: org.springframework.beans.factory.support.DefaultListableBeanFactory@5152a09f
    Mar 10, 2014 4:28:21 PM org.springframework.core.io.support.PropertiesLoaderSupport loadProperties
    INFO: Loading properties file from class path resource [properties/hibernate.properties]
    Mar 10, 2014 4:28:21 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@5152a09f: defining beans [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,dataSource,sessionFactory,transactionManager,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,aneurismLocationDAO,annotationDAO,appUserDAO,deviceDAO,deviceManufacturerDAO,jobDAO,patientDAO,resourceDAO,roleDAO,strategyDAO,surgeryDAO,surgeryDeviceDAO,userRoleDAO]; root of factory hierarchy
    Mar 10, 2014 4:28:21 PM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
    INFO: Loaded JDBC driver: com.mysql.jdbc.Driver
    37 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.5.5-Final
    39 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
    43 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
    47 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
    17632 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: org.e.models.Resource -> resource
    28298 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: org.e.models.Device -> device
    40931 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: org.e.models.AneurismLocation -> aneurism_location
    43487 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: org.e.models.Strategy -> strategy
    46348 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: org.e.models.Job -> job
    48916 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: org.e.models.SurgeryDevice -> surgery_device
    51356 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: org.e.models.UserRole -> user_role
    54070 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: org.e.models.Surgery -> surgery
    56434 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: org.e.models.Annotation1 -> annotation
    58732 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: org.e.models.Patient -> patient
    61120 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: org.e.models.Role -> role
    63747 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: org.e.models.DeviceManufacturer -> device_manufacturer
    66318 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: org.e.models.AppUser -> app_user
    Mar 10, 2014 4:29:28 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
    INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@5152a09f: defining beans [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,dataSource,sessionFactory,transactionManager,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,aneurismLocationDAO,annotationDAO,appUserDAO,deviceDAO,deviceManufacturerDAO,jobDAO,patientDAO,resourceDAO,roleDAO,strategyDAO,surgeryDAO,surgeryDeviceDAO,userRoleDAO]; root of factory hierarchy
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [database/hibernate.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Association references unmapped class: org.e.models.Annotation
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
        at Application.main(Application.java:23)
    Caused by: org.hibernate.MappingException: Association references unmapped class: org.endovantage.models.Annotation
        at org.hibernate.cfg.HbmBinder.bindCollectionSecondPass(HbmBinder.java:2473)
        at org.hibernate.cfg.HbmBinder$CollectionSecondPass.secondPass(HbmBinder.java:2752)
        at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:66)
        at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1221)
        at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1206)
        at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:673)
        at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
        ... 15 more

My models reside in another maven module.

This is the annotation hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Mar 5, 2014 5:28:21 PM by Hibernate Tools 4.0.0 -->
<hibernate-mapping>
    <class name="org.e.models.Annotation1" table="annotation" catalog="endo">
        <id name="id" type="java.lang.Long">
            <column name="id" />
            <generator class="identity" />
        </id>
        <many-to-one name="resource" class="org.e.models.Resource" fetch="select">
            <column name="resource_id" not-null="true" />
        </many-to-one>
        <property name="XPoint" type="java.lang.Integer">
            <column name="x_point" />
        </property>
        <property name="YPoint" type="java.lang.Integer">
            <column name="y_point" />
        </property>
        <property name="ZPoint" type="java.lang.Integer">
            <column name="z_point" />
        </property>
        <property name="comment" type="string">
            <column name="comment" length="65535" />
        </property>
    </class>
</hibernate-mapping>

This is my model for Annotation1 (I changed Annotation to Annotation1 to check weather this is the problem.)

   package org.e.models;

public class Annotation1 implements java.io.Serializable {

    private static final long serialVersionUID = 2037771233820433553L;
    private Long id;
    private Resource resource;
    private Integer XPoint;
    private Integer YPoint;
    private Integer ZPoint;
    private String comment;

    public Annotation1() {
    }

    public Annotation1(Resource resource) {
        this.resource = resource;
    }

    public Annotation1(Resource resource, Integer XPoint, Integer YPoint,
            Integer ZPoint, String comment) {
        this.resource = resource;
        this.XPoint = XPoint;
        this.YPoint = YPoint;
        this.ZPoint = ZPoint;
        this.comment = comment;
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Resource getResource() {
        return this.resource;
    }

    public void setResource(Resource resource) {
        this.resource = resource;
    }

    public Integer getXPoint() {
        return this.XPoint;
    }

    public void setXPoint(Integer XPoint) {
        this.XPoint = XPoint;
    }

    public Integer getYPoint() {
        return this.YPoint;
    }

    public void setYPoint(Integer YPoint) {
        this.YPoint = YPoint;
    }

    public Integer getZPoint() {
        return this.ZPoint;
    }

    public void setZPoint(Integer ZPoint) {
        this.ZPoint = ZPoint;
    }

    public String getComment() {
        return this.comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

}

This is my DAO implementation

    package org.e.persistance.dao.impli;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.e.models.Annotation1;
import org.e.persistance.dao.Annotation1DAO;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository("annotation1DAO")
public class Annotation1DAOImpli implements Annotation1DAO {

    private static final Log log = LogFactory.getLog(Annotation1DAOImpli.class);

    @Autowired
    private SessionFactory sessionFactory;

    public void persist(Annotation1 transientInstance) {
        log.debug("persisting Annotation1 instance");
        try {
            sessionFactory.getCurrentSession().persist(transientInstance);
            log.debug("persist successful");
        } catch (RuntimeException re) {
            log.error("persist failed", re);
            throw re;
        }
    }


    public void delete(Annotation1 persistentInstance) {
        log.debug("deleting Annotation1 instance");
        try {
            sessionFactory.getCurrentSession().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }

    public Annotation1 merge(Annotation1 detachedInstance) {
        log.debug("merging Annotation1 instance");
        try {
            Annotation1 result = (Annotation1) sessionFactory.getCurrentSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public Annotation1 findById(java.lang.Long id) {
        log.debug("getting Annotation1 instance with id: " + id);
        try {
            Annotation1 instance = (Annotation1) sessionFactory
                    .getCurrentSession().get("Annotation1", id);
            if (instance == null) {
                log.debug("get successful, no instance found");
            } else {
                log.debug("get successful, instance found");
            }
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }


}

Sorry for the long content. I really appreciate some help on this.

EDIT:

Hibernate configuration file

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <!-- Hibernate session factory -->
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

        <property name="dataSource">
            <ref bean="dataSource" />
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>

        <property name="mappingResources">
            <list>
                <value>/hibernate/Resource.hbm.xml</value>
                <value>/hibernate/Device.hbm.xml</value>
                <value>/hibernate/AneurismLocation.hbm.xml</value>
                <value>/hibernate/Strategy.hbm.xml</value>
                <value>/hibernate/Job.hbm.xml</value>
                <value>/hibernate/SurgeryDevice.hbm.xml</value>
                <value>/hibernate/UserRole.hbm.xml</value>
                <value>/hibernate/Surgery.hbm.xml</value>
                <value>/hibernate/Annotation1.hbm.xml</value>
                <value>/hibernate/Patient.hbm.xml</value>
                <value>/hibernate/Role.hbm.xml</value>
                <value>/hibernate/DeviceManufacturer.hbm.xml</value>
                <value>/hibernate/AppUser.hbm.xml</value>
            </list>
        </property>

    </bean>
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
</beans>

enter image description here

This is my data source configuration

    <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<bean 
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
        <value>properties/hibernate.properties</value>
    </property>
</bean>

<bean id="dataSource" 
         class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
</bean>

</beans>

This is my bean location configuration

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    <!-- Database Configuration -->
    <import resource="../database/dataSource.xml" />
    <import resource="../database/hibernate.xml" />
    <context:annotation-config />
    <context:component-scan base-package="org.endovantage" />
</beans>

Thanks

5
  • can u post ur hibernate configuration file Commented Mar 10, 2014 at 11:20
  • @henrycharles I have added my hibernate.xml Commented Mar 10, 2014 at 11:26
  • Your hibernate.xml is not a hibernate configuration file. Commented Mar 10, 2014 at 11:39
  • @PeterRader I will add all the configuration files I am using Commented Mar 10, 2014 at 11:40
  • Hi, everybody, Thanks for the big help. The reason it broke in the first place was that, the classes in the hbm.xml were not full qualified. After that I got the error most have mentioned the correct answer. So, I will +1 everybody! :) Commented Mar 13, 2014 at 9:30

3 Answers 3

2

You need to add a reference to the mapping file which maps org.e.models.Annotation1 into Hibernate.xmllike

<session-factory>
    <mapping resource="org/e/models/Annotation1.hbm.xml" />
</session-factory>
Sign up to request clarification or add additional context in comments.

5 Comments

I have added it to the hibernate.xml. Please see the edit. and thanks for the quick reply
@Diode It says there is a class org.endovantage.models.Annotation which doesn't have any mapping. Is that a duplicate of class org.e.models.Annotation1?
yes I looked at everywhere to see if there is any left out Annotation classes to rename manually. So is it that cause the probjem?
@Diode check package org.endovantage.models and remove Annotation.java if it is not necessary
I tried to remove that, It is becoming even worse. There one tp many relationships in the mapping :(
2

I think that you are missing this line:

<mapping resource="path/to/your/annotation.hbm.xml"></mapping>

in your hibernate.cfg.xml.

1 Comment

I am not using the hibernate.cfg.xml file. I was following this article. he has not included that. he has defined a hibernate.xml which I think the same content. plsease see the edit. and thanks a lot
1

Your class "Annotation" is not mapped. Add

 <value>/hibernate/Annotation1.hbm.xml</value>

And create the file if not exists.

1 Comment

Ok, I changed from Annotation to Annotation1 because I thought it was the cause of the problem. I will change everything back and check again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.