hi, all
I use xstream for serializing the objects that I load from database (mapped by hibernate) to a xml file. It works fine but when I try to load that object to db , I got some db exceptions like unique key violation or first insert the object b...
That is because of the many-to-one association.
(lets say A and B has many to one relation)
serializefile(session.find("Select from A").get(0), serializedfile);
// A is saved to file with associated attr B.
A a = deserializeFrom(serializedfile);
// the previously serialized A object is constructed from file
a.setName("namechanged");
// some attr. of a changed
session.saveOrUpdate(a);
// Error; here it gives "first insert the obj B..." error. But B is already in the database since it was loaded from there.
I load the associated B with A to the file and I reload that B with A to the db, but it says no such B in the db?
Why can this be occur?
* I do not map all of attributes of B,
Db manager should consider the same B's as 2 different object even if their id and all mapped attr. are equal???
* Can I put a some helpful info for the mapping file that helps db manager to understand that these 2 objects are equal?
<class A ....
...
...
<many-to-one name= "b" class= "B" column="bid" ..........
To sum up, how can easily manage saving and loading associations?
_________________ -developer
|