Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » History for OneToMany relationship with JoinColumn
History for OneToMany relationship with JoinColumn [message #1015025] Wed, 27 February 2013 08:47 Go to next message
Renso Lohuis is currently offline Renso LohuisFriend
Messages: 44
Registered: July 2012
Member
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 14:54 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

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.


James : Wiki : Book : Blog : Twitter
Previous Topic:Strange weaving message at startup
Next Topic:naming conflict on generating classes from xsd
Goto Forum:
  


Current Time: Fri Apr 19 11:52:11 GMT 2024

Powered by FUDForum. Page generated in 0.02138 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top