Announcement Announcement Module
Collapse
No announcement yet.
Hibernate MappingException: Unknown entity Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate MappingException: Unknown entity

    Hi all,

    I've got a system with 10 working mappings. when I tried to create the latest one I get the following error when trying to load or save a persistent object to it:

    Code:
    Unknown entity: za.co.telkom.ubr.model.CodeTemplate; nested exception is org.hibernate.MappingException: Unknown entity: za.co.telkom.ubr.model.CodeTemplate 
     
    org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: za.co.telkom.ubr.model.CodeTemplate; nested exception is org.hibernate.MappingException: Unknown entity: za.co.telkom.ubr.model.CodeTemplateorg.hibernate.MappingException: Unknown entity: za.co.telkom.ubr.model.CodeTemplate at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:550) at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:64) at org.hibernate.impl.SessionImpl.get(SessionImpl.java:577) at org.hibernate.impl.SessionImpl.get(SessionImpl.java:572) at org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:386) at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:310) at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:380) at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:375) at za.co.telkom.ubr.dao.hibernate.HibernateGenericDao.getObject(HibernateGenericDao.java:47) at za.co.telkom.ubr.service.impl.ConfigurationServiceImpl.loadCodeTemplate(ConfigurationServiceImpl.java:666) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:163) at $Proxy0.loadCodeTemplate(Unknown Source) at za.co.telkom.ubr.service.ConfigurationServiceTest.testLoadCodeTemplate(ConfigurationServiceTest.java:259) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    I'm using XDoclet to generate the hibernate mapping files (hbm.xml) and I've checked said files and they appear fine to me. Any Ideas?

    Thanks,
    Stefan

  • #2
    Check your mapping - you might have a reference to an unknown class (CodeTemplate).

    Comment


    • #3
      I am getting the same error telling me that there is an unknown mapping when using Spring. I am using spring-1.2 and hibernate-3.

      Whenever the following method is called in my DAO, I get the error.


      Code:
      protected void addItem(final Item item) {
          	HibernateTemplate hibernateTemplate =
                  new HibernateTemplate(getSessionFactory());
      
              hibernateTemplate.execute(
                  new HibernateCallback() {
                      public Object doInHibernate(Session session) throws HibernateException {
                              //session.getSessionFactory().getAllClassMetaData() returns an empty
                              //map so the  next line causes 
                              //org.hibernate.MappingException: Unknown entity
                      	return session.save(item); //throws 
                      }
                  }
              );    	
          }
      I know that there isn't a problem with my mapping xml file because it works fine in the following (using the same hibernate configuration):
      Code:
      Session s = HibernateUtil.currentSession();
      s.save(item);

      TIA

      Comment


      • #4
        HibernateMapping: Unknown entity solution

        If you were already using hibernate in your project (before spring) then you could just call
        new Configuration().configure().buildSessionFactory() to create a session factory and all of the mapping resources referenced in the hibernate.cfg.xml document would be available.

        Don't specify hibernate.cfg.xml as a mapping resource in your spring application context. Specify each hbm.xml XML configuration like so:

        Code:
        <bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
               <property name="mappingResources">
                   <list>
                       <value>Item1.hbm.xml</value>
                       <value>Item2.hbm.xml</value>
                       ...
                       <value>ItemN.hbm.xml</value>
                   </list>
               </property>
               ...
           </bean>
        [/b]

        Comment


        • #5
          I found my problem, I have a hibernate context file which lists the hbm.xml files for my model classes:

          Code:
              <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
                  <property name="dataSource"><ref bean="dataSource"/></property>
                  <property name="mappingResources">
                      <list>
                          <value>za/co/telkom/ubr/model/Aspect.hbm.xml</value>
                          <value>za/co/telkom/ubr/model/Dbms.hbm.xml</value>
                          .
                          .
                          .
          I omitted to add the new model class to the list. As soon as I did that the problem was solved.

          Regards,
          Stefan

          Comment


          • #6
            org.hibernate.MappingException: Unknown entity: on annotated class

            Hi
            I have an annotated class and do NOT have a mapping file. Yet I am getting:

            Caused by: org.hibernate.MappingException: Unknown entity: org.springframework.samples.petclinic.Manvita
            at org.hibernate.impl.SessionFactoryImpl.getEntityPer sister(SessionFactoryImpl.java:548)
            at org.hibernate.impl.SessionImpl.getEntityPersister( SessionImpl.java:1338)

            And the file is marked up as:

            @Entity
            public class Manvita implements Serializable {

            Any ideas?

            Thanks.

            Comment


            • #7
              annotatedClass-NotFoundEntity

              hi :-)
              I hane the same problem as you. (at annotated class: no found entity)
              Did you find the solution?

              Comment


              • #8
                org.hibernate.MappingException: Unknown entity: on annotated class

                hi :-)

                I have an annotated class and I get
                org.hibernate.MappingException: Unknown entity:

                Does anyone knows how to resolve this problem?thanks

                Comment


                • #9
                  I would presume this is a similar issue, how to you name the classes Hibernate should know about?

                  Comment


                  • #10
                    problem resolved

                    Thanks. I resolved the problem :-)

                    Comment


                    • #11
                      Any chance you could post the details, it's always useful for other people to know what solved it!

                      Comment


                      • #12
                        it depends on classloading

                        Hi
                        When you run in a servlet container the annotated classes are picked up correctly. When you run from Eclipse or Maven (testing), then you need to specify the annotated classes explicitly in /META-INF/persistence.xml:
                        Code:
                        <persistence xmlns="http://java.sun.com/xml/ns/persistence"
                        	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
                        	version="1.0">
                        
                        	<persistence-unit name="MyTest" transaction-type="RESOURCE_LOCAL">
                                <class>com.wellsfargo.blackjack.model.user.User</class>
                                <class>com.wellsfargo.blackjack.model.user.UserInfo</class>
                                <class>com.wellsfargo.blackjack.model.user.CreditCard</class>
                                ..
                        		<properties>
                        			<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/>
                                    <property name="hibernate.show_sql" value="true"/>
                                    <property name="hibernate.use_outer_join" value="false"/>
                                </properties>
                                
                        	</persistence-unit>
                        </persistence>
                        I hope this helps.

                        Comment


                        • #13
                          Solution?

                          Originally posted by niki View Post
                          Thanks. I resolved the problem :-)
                          How you solved the problem? I got the same problem...

                          Thx.

                          juergen

                          Comment


                          • #14
                            In case, someone else would come cross that problem ... i have solved the problem by using org.springframework.orm.hibernate3.annotation.Anno tationSessionFactoryBean in applicationContext.xml file, in order to use mixture of annotation and hbm.xml mapping resource at same time in hibernate and spring ...



                            <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotati on.AnnotationSessionFactoryBean">

                            <property name="dataSource" ref="myDataSource" />
                            <property name="hibernateProperties">
                            <props>
                            <prop key="hibernate.dialect">org.hibernate.dialect.MySQ LDialect</prop>
                            </props>
                            </property>
                            <property name="annotatedClasses">
                            <list>
                            <value>x.y.z.db.pojo.A</value>
                            </list>
                            </property>
                            <property name="mappingResources">
                            <list>
                            <value>com/x/y/z/db/pojo/B.hbm.xml</value>
                            <value>com/x/y/z/db/pojo/C.hbm.xml</value>
                            ....
                            </list>
                            </property>
                            </bean>

                            i hope this helps ...


                            Deniz
                            Last edited by denizstij; Oct 4th, 2007, 05:48 AM.

                            Comment


                            • #15
                              What is the real problem ?

                              I have the same problem... i can run it in unit test.
                              But when I deploy it in Tomcat the "Unknown entity" error come out.
                              I'm using Entity annotation in all my entity class ...

                              Please help, if anyone have any information.
                              Thanks.

                              Comment

                              Working...
                              X