-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: An association from the table refers to an unmapped class:
PostPosted: Wed Nov 16, 2005 6:15 pm 
Newbie

Joined: Wed Nov 16, 2005 1:55 pm
Posts: 12
Can someone help me with this.. I dont really understand why hibernate is doin this..

An association from the table blogs refers to an unmapped class: java.lang.Integer

i dont see this anywhere in the mapping file..


Hibernate version:
3.0.5
Mapping documents:
blogs table mapping file
Code:
<hibernate-mapping>

    <class name="com.insaini.publogs.hibernate.tables.Blogs" table="blogs">
        <id name="id" column="id" type="java.lang.Integer">
            <generator class="native"/>
        </id>

        <property name="name" column="name" type="java.lang.String"  not-null="true" />
        <property name="body" column="body" type="java.lang.String"  not-null="true" />
        <property name="numviewed" column="numViewed" type="java.lang.Integer"  not-null="true" />
        <property name="status" column="status" type="java.lang.Integer" />
        <property name="datecreated" column="dateCreated" type="java.util.Date"  not-null="true" />
        <property name="datemodified" column="dateModified" type="java.util.Date"  not-null="true" />
                   
       <many-to-one name="userid" column="userId" not-null="true" />           
       <many-to-one name="formatid" column="formatId" not-null="false"/>      
       <many-to-one name="topicid" column="topicId" not-null="false"/>             
      
       <set name="user_ratings" table="user_blog_rating" inverse="false">
           <key column="blogId" not-null="true"/>
           <many-to-many column="userId" class="com.insaini.publogs.hibernate.tables.Users"/>
       </set>                           
    </class>

</hibernate-mapping>



Name and version of the database you are using:
MySQL 5.0.15
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
Code:
INFO main org.hibernate.cfg.Configuration - processing association property references
INFO main org.hibernate.cfg.Configuration - processing foreign key constraints
DEBUG main org.hibernate.cfg.Configuration - resolving reference to class: com.insaini.publogs.hibernate.tables.Topics
DEBUG main org.hibernate.cfg.Configuration - resolving reference to class: com.insaini.publogs.hibernate.tables.Sections
DEBUG main org.hibernate.cfg.Configuration - resolving reference to class: com.insaini.publogs.hibernate.tables.UserFormats
DEBUG main org.hibernate.cfg.Configuration - resolving reference to class: java.lang.Integer
ERROR main com.insaini.publogs.struts.HibernatePlugIn - Exception while initializing Hibernate.
ERROR main com.insaini.publogs.struts.HibernatePlugIn - Rethrowing exception...
org.hibernate.MappingException: An association from the table blogs refers to an unmapped class: java.lang.Integer
   at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:968)
   at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:921)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:999)
   at com.insaini.publogs.struts.HibernatePlugIn.initHibernate(HibernatePlugIn.java:118)
   at com.insaini.publogs.struts.HibernatePlugIn.init(HibernatePlugIn.java:95)
   at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:869)
   at org.apache.struts.action.ActionServlet.init(ActionServlet.java:336)
   at javax.servlet.GenericServlet.init(GenericServlet.java:211)
   at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1091)
   at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:925)
   at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3880)
   at org.apache.catalina.core.StandardContext.start(StandardContext.java:4141)
   at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
   at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
   at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
   at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:603)
   at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:535)
   at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:470)
   at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1118)
   at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
   at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
   at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1020)
   at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
   at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)
   at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
   at org.apache.catalina.core.StandardService.start(StandardService.java:450)
   at org.apache.catalina.core.StandardServer.start(StandardServer.java:680)
   at org.apache.catalina.startup.Catalina.start(Catalina.java:536)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:275)
   at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 9:40 pm 
Newbie

Joined: Wed Nov 16, 2005 1:55 pm
Posts: 12
Basically..

There are three tables

Users, Blogs and User_Blogs

User_Blogs has a composite id (userId,blogId)

here is my user_blog mapping file

Code:
<hibernate-mapping package="com.insaini.publogs.hibernate.tables">

    <class name="UserBlogRating" table="user_blog_rating">
        <composite-id name="id" class="UserBlogRatingKey">
            <key-many-to-one name="blogid" column="blogId" />
            <key-many-to-one name="userid" column="userId" />
        </composite-id>

        <property name="rating" column="rating" type="integer"  not-null="true" />
      
    </class>
   
</hibernate-mapping>


my blog mapping file is above..

there is a many to many relationship between blogs and users so obviously there is a one-to-many relationship between users and user_blogs and one-to-many relationship between blogs and user_blogs

how exactly do i setup the relationships in these mapping files?

thanks

jazz


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 10:18 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
Code:
       <many-to-one name="userid" column="userId" not-null="true" />           
       <many-to-one name="formatid" column="formatId" not-null="false"/>       
       <many-to-one name="topicid" column="topicId" not-null="false"/>


Look at these three ... find the property in Blogs that corresponds to each and then look at the mapping file you have for the property type. In one of those mappings, is the name attribute of the class element set to java.lang.Integer ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 10:48 pm 
Newbie

Joined: Wed Nov 16, 2005 1:55 pm
Posts: 12
Hi,

No I am using hibernate data types..

the mapping file uses "integer" instead of "java.lang.Integer" ..

here is my blogs mapping file again this time i added in the properties for the many-to-one foreign keys

Code:
<hibernate-mapping package="com.insaini.publogs.hibernate.tables">

    <class name="Blogs" table="blogs">
        <id name="id" column="id" type="integer">
            <generator class="native"/>
        </id>

        <property name="name" column="name" type="serializable"  not-null="true" />
        <property name="body" column="body" type="serializable"  not-null="true" />
        <property name="numviewed" column="numViewed" type="integer"  not-null="true" />
        <property name="status" column="status" type="integer" />
        <property name="datecreated" column="dateCreated" type="timestamp"  not-null="true" />
        <property name="datemodified" column="dateModified" type="timestamp"  not-null="true" />
      <property name="userid" column="userId" type="integer"  not-null="true" />
      <property name="formatid" column="formatId" type="integer"  not-null="false" />
      <property name="topicid" column="topicId" type="integer"  not-null="false" />
      <property name="blogid" column="blogId" type="integer"  not-null="false" />
      
       <many-to-one name="userid" column="userId" not-null="true" />           
       <many-to-one name="formatid" column="formatId" not-null="false"/>      
       <many-to-one name="topicid" column="topicId" not-null="false"/>      
       <many-to-one name="blogid" column="blogId" not-null="false"/>         
      
        <set name="user_ratings" table="user_blog_rating" inverse="false">
           <key>
              <column name="userId" not-null="true" />
              <column name="blogId" not-null="true" />
           </key>
           <many-to-many column="userId" class="Users"/>
        </set> 
    </class>
   
</hibernate-mapping>


i still get

org.hibernate.MappingException: An association from the table blogs refers to an unmapped class: java.lang.Integer

its too bad the log just doesnt say which tag exactly is giving this problem.. it just says blogs table and this mapping refers to the blogs table. the Blogs class uses java.lang.Integer however.. but these files were auto generated by eclipse


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 10:51 pm 
Newbie

Joined: Wed Nov 16, 2005 1:55 pm
Posts: 12
and ive gone through every mapping file and anywhere the Class attribute is specified.. no where does it say java.lang.Integer


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 10:53 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
and this is the only class mapped to the blogs table ? try removing the properties in this mapping one by one and narrow this down.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 11:00 pm 
Newbie

Joined: Wed Nov 16, 2005 1:55 pm
Posts: 12
oohh.. thank you very much man i just realized what the problem was..

its discussed in detail here and solved the problem perfectly!

http://jira.jboss.com/jira/browse/JBDOCS-165

"When the "class" attribute is not specified for the "many-to-one" tag, it is assumed that the class's name is the value for the "name" attribute, with the first letter capitalized. In the above case, the class is assumed to also be called "Address". If "Address" is not mapped, then an exception is thrown

The documentation should mention that the "class" attribute is required whenever the class name and the association name differ. This could be mentioned in the introduction or stated after each place where a many-to-one association is used."

thanks!

Jazz


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 11:02 pm 
Newbie

Joined: Wed Nov 16, 2005 1:55 pm
Posts: 12
all the tags.. where i didnt have the Class attribute set in the many-to-one elements.. it was assumed to cast to Integer because thats what the key field is.. however i need it to cast to the proper class of Blogs or whatever.. so i have to add the class element and explicitly state the class to cast to


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.