In my code I use both native SQL and HQL. My mapping is:
Code:
<class name="User" table="users">
...
<set name="attributes" inverse="true" lazy="true" cascade="all">
<key column="userId" />
<one-to-many class="Attribute" />
</set>
</class>
I load User object using Hibernate: session.load(...)
Because lazy is true in attributes set, the attributes are not loaded. Next, I fetch the attributes with native SQL query by hand (ie. not using Hibernate) and setting them one by one to User object with:
Code:
Set ua = user.getAttributes();
ua.add(a);
user.setAttributes(ua);
Unfortunately what happens here is that when I call user.getAttributes() they are all loaded by Hibernate (of course!!) and this is exactly what I DON'T want. Is there any way to prevent Hibernate from loading the attributes in this case (there are cases where I DO need Hibernate to load the attributes)?
I think this is impossible, but someone please correct me if I'm wrong (I sure hope so!!)
Thanks!
ps. this is just an example of my problem, my real code is not that simple, but you get the idea of the problem here... :)