so following situation:
I am using Hibernate to upload/download data to and from the database, which works fine.
Currently I have two tables, "Parent"(which is the parent) and "Child"(which is the child). I have a OneToMany / ManyToOne relationship. I only upload the parent and the child is automatically uploaded due to cascade. The Parent.class has a List(Child).
If an entity of "Parent" is changed/updated, I want to move the "old version" into a table called "Parent_OLD" (and of course the child via cascade) and add a time stamp to the old entity.
So the problem I am currently encountering is: I have tried to solve it by creating a new class "Parent_OLD" which looks exactly like the "Parent" except for the time stamp. So what I did is: Whenever I upload new data to the DB, I check if the entity already exists and if it does I pass the data via "getters" to "Parent_OLD". This works fine so far, because I only have like 3 attributes I need to pass, but if I end up with more fields, it would be handy to have a different solution to this.
But what does not work is to move the "child_OLD" to the "Child_OLD". So as mentioned above, the Parent.class has a List(Child). Child_NEW and Child_OLD actually look exactly alike, because they do not need a time stamp. But due to the Hibernate Annotation on top of the Child.class every entity of Child.class is loaded into "Child"-table.
So I created a Child_OLD.class. This means: I have a current Parent entity, with a List(Child). I want to pass the parent (including the list) to the Parent_OLD entity.
But I cannot cast the List(Child) to List(Child_OLD). I have tried casting it to a list of objects and then to Child_OLD, but this did not work. Passing the attributes via "getters" is no option as the class has like 60 fields. I also tried creating an abstract class "Child" but I still did not manage to get it to work.
So I thought it would be amazingly simple if I could tell Hibernate to load certain entities into a different table. So maybe something like an annotation above the CheckIfExistsAndIfItDoesCopyToOldTable-Method. Is this possible? Or does anyone know how I could solve my problem?
I guess I need to apologize because I do not know how clear I managed to explain my problem. So sorry for the possibly confusing text and thank you in advance for your ideas!
Edit: I want to backup the Parent as well as the Child. But this should happen via cascade if possible. So, by backing up the Parent, the List with the children should be moved into the Child-BackUp-Table.