Hello,
I've got general knowledge about hibernate, but I've got a problem, which is for sure pretty easy to solve by an expert.
This is a snippet of my model:
(Offer can have many OfferParts)
Code:
public class Offer {
... //the main part is the collection
private Set parts = new HashSet();
...
public class OfferPart {
...
private Offer offer;
...
and mapping:
Offer:
Code:
...
<set name="parts" inverse="true" >
<key column="part_id" on-delete="cascade" />
<one-to-many class="OfferPart" />
</set>
...
OfferPart:
Code:
...
<many-to-one name="offer" class="Offer"
column="offer_id" not-null="true" />
...
And now when I initilize my application with example data:
Code:
Offer offer = new Offer();
session.save(offer);
OfferPart part = new OfferPart();
part.setOffer(offer);
session.save(part);
OfferPart part2 = new OfferPart();
part2.setOffer(offer);
session.save(part);
and later do smth like this:
Code:
System.out.println(offer.getParts())
and I get "[]", although I think I've added two parts to to set(with this part2.setOffer(offer)).
It isn't lazy initialization I think, becouse there aren't any exception.
Please explain it to me.