Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.1.2
I use entity-name to map one object into 2 tables: the "real" objects and the "archived" ones: i duplicate the hbm files, and replace some class="..." with entity-name="...".
Now i want to move a record from the real table into the archived table:
session.delete("real",o); session.save("archived",o);
Actually my object isn't just an object, it's a thing that is mapped to 3 tables (one for the object, one for a related set of objects, and another one-to-one table). So now i have 3 pairs of tables, and 3 pairs of hbm's (looking alike, but slightly different in their many-to-one an one-to-one).
Note that the object also relates to other tables (it has FK's pointing to other tables), which are not duplicated.
1) What's the best way to move a record, with all its related records, from the "real" tables, into the "archived" tables? Since all info is in the mapping files, i think hibernate should be able to do the "deep" copy...
2) What happens with o.getRelatedObjects(), when persistent object o is persisted in table 1, and is suddenly pushed in table 2 by doing save("table2",object)?
3) How can i make my object o transient, without deleting the record from the database? Hibernate.initialize(o.getRelatedObjects()), detach o (close session, and start another one), and invoke save("table2",o) in a fresh session, and cascade="all"?