1

I have an entity that has reference to another entity that represents the current state of certain properties, thus allowing me to keep track of the history of changes made. For this, I have defined a bidirectional relation that is not symmetric, with the OneToOne being responsible for the persistence, and both entities keeping a reference to the other one so I can from one side get the latest version, and on the other side get all the versions for the entity. This is my mapping:

In the A entity:

@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "version_id", nullable = true, updatable = true)
private AVersion currentVersion;

and in the AVersion entity:

@ManyToOne
@JoinColumn(name = "A_id", insertable=false, updatable=false)
private A a;

Now, this allows me to persist this in one step through A, but the column "A_id" is empty for every row in the AVersion table, so I won't be able to retrieve all the historical data for a certain entity A looking in the AVersion table. Any idea why this column is not being filled?

Thank you very much!

P.S. I have tried using Envers, but couldn't because of some inheritance problems.

igracia
  • 3,543
  • 1
  • 18
  • 23
  • 1
    Well, have to say that I finally couldn't do this. I think that assymmetric bidirectional mappings are not supported. Anyway, I think that envers could have helped with getting rid of the versions and so on, since they corrected their inheritance issue, or I could just have retreived the latest version with a query, instead of having that mapping... but finally opted to persist the parent entity with null AVersion, and then update it with the parent-chil relation set. – igracia Mar 02 '12 at 16:47

0 Answers0