Hi,
I have a wierd problem when saving data in a specific scenario. Since this can potentially cause havoc, I am hoping someone can provide a solution.
I have 3 objects.
ObjectA is mapped in Hibernate using .hbm file
ObjectB is a member of ObjectA and does not need to be stored.
ObjectC is a member of ObjectB and is mapped in Hibernate using .hbm file
In the program, I do this.
Session session = sessionFactory.openSession();
// Change the state of ObjectA
// Change the state of ObjectC
Transaction t = session.beginTransaction();
session.save(ObjectA);
t.commit();
Now, even though ObjectB does not have any mapping in Hibernate, the Session still keeps track of changes to ObjectC (which is inside ObjectB) and saves it when I try to save ObjectA, although I want to save only ObjectA and not ObjectC.
While I understand that ObjectC is reachable from ObjectA, what I don't understand is how it can save it when ObjectB, which is sitting in the middle has no explicit database mapping.
I tried making ObjectB transient, and it did not work. Since ObjectB has no Hibernate mapping, I cannot say "cascade="none"" also.
Is there any workaround for this problem?
Sathya.
|