Announcement Announcement Module
Collapse
No announcement yet.
net.sf.hibernate.MappingException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • net.sf.hibernate.MappingException

    With the following mapping value:
    <value>com/bd/profit/model/ReportType.hbm.xml</value>

    and a ReportType.java, ReportType.hbm.xml file I get the following error in an Ant Build script utilizing junit test.


    [junit] ------------- Standard Output ---------------
    [junit] org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'sessionFactory' defined in class path resource [application-context.xml]: Initialization of bean failed; nested exception is net.sf.hibernate.MappingException: persistent class [com.bd.profit.model.Type] not found


    However, when I change the name to ReportTyp in all areas, everything works fine...


    any ideas?

  • #2
    Nick,

    If your Java class is called ReportType then your Hibernate mapping should to be this class. If you look at the stack trace, Hibernate is looking for a class called simply Type which is says does not exist on the classpath.

    Rob

    Comment


    • #3
      Mapping seems to be Ok

      application-context.xml

      <bean id="sessionFactory"
      class="org.springframework.orm.hibernate.LocalSess ionFactoryBean">

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

      <property name="mappingResources">
      <list>

      <value>com/bd/profit/model/ReportType.hbm.xml</value>
      </list>
      </property>

      Then, I also have ReportType.java and ReportType.hbm.xml
      When I rename all to ReportTyp everything works fine...
      [/b]

      Comment


      • #4
        It's definitely a problem in your Hibernate mapping file. Have you checked it doesn't specify ReportTyp?

        Comment


        • #5
          Not a mapping problem

          im pretty sure its not in the hibernate mapping file, and that it doesnt like the term ReportType for some reason... here is my mapping file and code...

          application-context.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="propertyConfigurer"
          class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
          <property name="locations">
          <list>
          <value>hibernate.properties</value>
          </list>
          </property>
          </bean>


          <bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
          <property name="driverClassName">
          <value>oracle.jdbc.driver.OracleDriver</value>
          </property>
          <property name="url">
          <value>jdbc:oracle:thin:@md11000:1521:md11000</value>
          </property>
          <property name="username">
          <value>${hib.username}</value>
          </property>
          <property name="password">
          <value>${hib.password}</value>
          </property>
          </bean>

          <bean id="sessionFactory"
          class="org.springframework.orm.hibernate.LocalSess ionFactoryBean">

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

          <property name="mappingResources">
          <list>
          <value>com/bd/profit/model/ReportType.hbm.xml</value>

          </list>
          </property>

          <property name="hibernateProperties">
          <props>
          <prop key="hibernate.show_sql">true</prop>
          <prop key="hibernate.dialect">
          net.sf.hibernate.dialect.Oracle9Dialect
          </prop>
          </props>
          </property>
          </bean>

          <bean id="ReportTypeDao"
          class="com.bd.profit.dao.hibernate.DaoHibernate">
          <property name="sessionFactory">
          <ref local="sessionFactory" />
          </property>
          </bean>


          </beans>

          DaoHibernate.java


          /**
          * The DAOHibernate class.
          *
          * @author christy
          * @since Feb 1, 2005
          */
          public class DaoHibernate extends HibernateDaoSupport implements IDao {

          /**
          *
          */
          public DaoHibernate() {
          super();
          // TODO Auto-generated constructor stub
          }

          /**
          * @param fromClause
          * @return List
          */
          public List getAll(String fromClause) {
          return getHibernateTemplate().find(fromClause);
          }

          /**
          * @param clazz
          * @param id
          * @return Object
          */
          public Object get(Class clazz, Long id) {

          return getHibernateTemplate().get(clazz, id);
          }

          /**
          * @param object
          */
          public void save(Object object) {
          getHibernateTemplate().saveOrUpdate(object);
          }

          /**
          * @param clazz
          * @param id
          */
          public void remove(Class clazz,Long id) {
          Object object = getHibernateTemplate().load(clazz,id);
          getHibernateTemplate().delete(object);
          }


          }


          ReportType.java


          /**
          * The ReportType class.
          *
          * @author christy
          * @since Feb 1, 2005
          */
          public class ReportType extends AbstractModel {

          private String description;

          /**
          *
          *
          */
          public ReportType() {
          //
          }
          /**
          *
          */
          public ReportType(Long id) {
          super(id);
          }

          /**
          *
          * @param reportName
          */
          public ReportType(String reportName) {
          this.description = reportName;
          }

          /**
          *
          * @return String
          */
          public String getDescription() {
          return description;
          }

          /**
          *
          * @param description
          */
          public void setDescription(String description) {
          this.description = description;
          }

          }


          ReportType.hbm.xml

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

          <hibernate-mapping package="com.bd.profit.model">

          <class name="ReportType" table="REPORT_TYPE" lazy="true">
          <id name="id" column="REPORT_TYPE_UI" type="java.lang.Long">
          <generator class="sequence">
          <param name="sequence">seq_report_type</param>
          </generator>
          </id>

          <property name="description" column="REPORT_TYPE_DESC" type="java.lang.String" />
          </class>

          </hibernate-mapping>



          TestReportType.java


          /**
          * The testReportType class.
          *
          * @author christy
          * @since Feb 1, 2005
          */
          public class TestReportType extends BaseTest {

          /**
          *
          */
          public TestReportType() {
          super();
          }


          public void setUp() throws Exception {
          super.setUp("ReportTypeDao",ReportType.class);
          }
          /* (non-Javadoc)
          * @see com.bd.hibernate.sandbox.test.IDaoTest#testGet()
          */
          public void testGet() {
          super.testGet();
          }

          /* (non-Javadoc)
          * @see com.bd.hibernate.sandbox.test.IDaoTest#testGetAll( )
          */
          public void testGetAll() {
          super.testGetAll("from ReportType");
          }

          /* (non-Javadoc)
          * @see com.bd.hibernate.sandbox.test.IDaoTest#testSave()
          */
          public void testSave() {
          dao.save(super.getReportType());
          }

          /* (non-Javadoc)
          * @see com.bd.hibernate.sandbox.test.IDaoTest#testRemove( )
          */
          public void testRemove() {
          super.testRemove();
          }

          public void tearDown() throws Exception {
          super.tearDown();
          }

          }



          Now when I take that exact code and replace ReportType.java with ReportTyp.java everything works fine, this is why I do not think it is a mapping problem

          Comment


          • #6
            replace all ReportType with ReportTyp

            Sorry, not just the file ReportType.java with ReportTyp.java it works fine when I replace all occurences of ReportType with ReportTyp

            Comment

            Working...
            X