Hi,
Suppose you have a Car that has a set of many Parts, mapped as:
Code:
(in Car's mapping)
<set name="parts">
<key column="car_id" not-null="true" />
<one-to-many class="Part" />
</set>
Now, say you want to build a servlet that queries for Cars and returns them, and the client wants to display the Car and all its Parts. How do you do this? My call to the servlet keeps failing..
I tried adding 'lazy="false"' to the <set> but to no avail. In the Eclipse debugger, I'm seeing that the Hibernate-generated Car contains a PersistentSet as its set... Is that not serializable? If I copy all the elements from that PersistentSet into a HashSet and set the HashSet as the Car's parts, it works... But this is just nasty..
Beyond that, having a lazy=false is non-ideal. Sometimes I want to return info to the client, so I want it to initialize everything, while sometimes I'm just dealing with partial data within the server, in which case I'm happy to let it be lazy. Is there a way to tell Hibernate which queries you want to have executed lazily on the fly?
BTW, I'm using GWT, so my client is also written in Java.. The client and server share the same POJOs. The error I'm seeing says "The call failed on the server; see server log for details", but unfortunately I cannot find anything in the server logs (???). [I'm also new to GWT.. sigh]
To recap, my questions are:
1. Is PersistentSet not serializable?
2. How can I deal with this issue, beside adding all the elements of the PersistentSet to a HashSet and returning that?
3. Is there a way to programmatically tell Hibernate which queries I want it to perform lazily?
Thanks in advance, and sorry for my n00bness