History for OneToMany relationship with JoinColumn [message #1015025] |
Wed, 27 February 2013 03:47  |
Eclipse User |
|
|
|
I want to use EclipseLink Jpa History for a OneToMany relationship simular to the following example
@Entity
class Movie {
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "MOVIE_ID")
private List<Review> reviewList;
}
@Entity
class Review {
}
When I define history policy for movie and review it will maintain history. But It won't save the MOVIE_ID in the Review history table (while it is saved in the Review table).
I found out that first a Review is inserted, then it is inserted in the history table and then it will set the movie id (with an update query), but it won't update the history table.
I did found a way to do it. If I change it the the following and set the movie on the review entity. It works fine (MOVIE_ID is set at the insert).
@Entity
class Movie {
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true, mappedBy="movie")
private List<Review> reviewList;
}
@Entity
class Review {
@ManyToOne
@JoinColumn(nullable = false)
public Movie movie;
}
I rather have the use the first code, because it less chance I forget to set the Movie and it is faster at inserts. And I don't need the movie at the review entity.
Is there a way to get it to work the with @JoinColumn like the first example?
|
|
|
Re: History for OneToMany relationship with JoinColumn [message #1016228 is a reply to message #1015025] |
Tue, 05 March 2013 09:54  |
Eclipse User |
|
|
|
Using a mappedBy is the normal and best way to define a @OneToMany, I would recommend sticking with it.
The OneToMany with a JoinColumn is a specialized type of mapping that allows the source object to store the join column into the target object's table. Because they target object knows nothing about this column, this involves a lot of extra work.
Currently history does not support this specialized UnidirectionalOneToManyMapping, please log a bug to have this support added.
|
|
|
Powered by
FUDForum. Page generated in 0.03335 seconds