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.  [ 2 posts ] 
Author Message
 Post subject: Retrieval Problem with many-to-one mapping. Plz help...
PostPosted: Thu Oct 04, 2007 1:25 am 
Newbie

Joined: Sat Sep 29, 2007 12:54 am
Posts: 3
Hi All
I am new to hibernate.
I am trying to do many-to-one mapping in hibernate.
I am using 2 tables :

1) UserTypes(usertypesid is primary key)
2) Users (userid is primary key and usertypesid is foreign key from usertypes table.)



Code:
    The XML file for UserTypes table is as follows:
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
       "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
       "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>
     
        <class name="com.useradmin.beans.admin.UserTypes" table="usertypes"  >
         <id name="id" column="typeid" unsaved-value="0">
                <generator class="increment" />
         </id>
            <property name="typeName" column="typeName" not-null="true" length="50"/>
           
        <set name="users" lazy="true" inverse="true" cascade="all-delete-orphan">
          <key column="userid" />
          <one-to-many class="com.useradmin.beans.admin.User" />
       </set>
     
     </class>
    </hibernate-mapping>



And for the users table is as follows:

Code:

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
       "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
       "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>
        <class name="com.useradmin.beans.admin.User" table="users">
            <id name="id" column="userid" unsaved-value="0">
                <generator class="increment" />
            </id>
         
             <many-to-one  name="usertypes" column="typeid"  class="com.useradmin.beans.admin.UserTypes" lazy="false" not-null="true">
             </many-to-one>
             
          <property name="firstname" column="firstname"   not-null="false" length="50"/>   
            <property name="lastName" column="lastname"  not-null="false" length="16"></property>
            <property name="address" column="address"  not-null="false" length="16"/>
            <property name="email" column="email" not-null="false"/>
            <property name="login" column="login"  not-null="false" length="50"></property>
            <property name="password" column="password"  not-null="false" length="50"/>               
           
        </class>
     
    </hibernate-mapping>





I have been able to insert the records into user tables by mapping successfully but the problem comes when i try to retrieve the records from userypes table..
It also retrieve the records from the user table i dnt knw y??

I have tried all the forums and articles now this is my last hope. Please help me if anybody has any idea.
The hql for usertypes is "


Code:
    from usertypes"



And this is generating the sql like the followings:


Code:
    Hibernate: select usertypes0_.typeid as typeid1_, usertypes0_.typeName as typeName1_ from usertypes usertypes0_
    Hibernate: select user0_.userid as userid3_, user0_.typeid as typeid3_, user0_.firstname as firstname3_, user0_.lastname as lastname3_, user0_.address as address3_, user0_.email as email3_, user0_.login as login3_, user0_.password as password3_ from users user0_



I am not able to understand y its also showing the select sql from user table?
Anybody has any idea advise my..
Thanks a lot..


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 04, 2007 3:50 am 
Newbie

Joined: Sat Sep 29, 2007 12:54 am
Posts: 3
i have solved it by myself after 3 weeks :)
if anybody will encounter this in future u can ask me at chahal_khushwinder@yahoo.co.in
thanx a lot


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.