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..
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).
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.
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.