• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate Mapping (Many-To-One Association). Problem. This forum is my last hope.

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.)


And for the users table is as follows:




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 "

And this is generating the sql like the followings:


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..
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't seem to have a proxy interface defined for either class. Hibernate needs a proxy to implement lazy initialization, without it the lazy="true" attributes of your association mapping are meaningless (true is the default anyway, so this attribute is unnecessary unless you want to disable lazy initialization for this particular association).
 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Paul for your feedback.
According to you:
1) i need to do implement proxy interface for my classes
2) I need to give lazy="false" in spite of lazy="true"

Would you like to add something for further explain your answer?
I will highly appreciate your valuable suggestions..

Thanks once again.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


According to you:
1) i need to do implement proxy interface for my classes


Yes, though the normal route is to let the class itself can behave as its own proxy. Add a proxy attribute to your class mapping (see the Hibernate documentation if you)


2) I need to give lazy="false" in spite of lazy="true"


No. All associations in Hibernate are by default lazy. If you don't have a proxy class to implement this lazy initialization though then the lazy attribute is meaningless. You can use lazy="true" for clarity's sake (which is what I tend to do) but it is not necessary.
 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply Paul.
I am doing exactly as per your saying.
i have given proxy as same as the class name and lazy="true".
But the output is still same.
I also have read 100s of examples on the net they have not given that
the proxy attribute is necessary.
I am unable to figure out the problem with my code.
 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have solved it by myself after 3 weeks
if anybody will encounter this in future you can ask me at chahal_khushwinder@yahoo.co.in
thanks a lot
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by khushwinder khushwinder:
i have solved it by myself after 3 weeks
if anybody will encounter this in future you can ask me at
thanks a lot



Or you can post it in the forum. It is probably best not to post your email address in a forum, because you will most likely receive more spam.

Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic