开发者

Mapping bidirectional asymmetric relation in hibernate: OneToOne-ManyToOne

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开发者_StackOverflow 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜