| While working on the hibernate-demos project we had to apply the following change: from
public Hike createHike(Hike hike, Trip recommendedTrip) {
entityManager.persist( hike );
if ( recommendedTrip != null ) {
recommendedTrip = entityManager.merge( recommendedTrip );
hike.recommendedTrip = recommendedTrip;
recommendedTrip.availableHikes.add( hike );
}
return hike;
}
to
public Hike createHike(Hike hike, Trip recommendedTrip) {
if ( recommendedTrip != null ) {
recommendedTrip = entityManager.merge( recommendedTrip );
hike.recommendedTrip = recommendedTrip;
recommendedTrip.availableHikes.add( hike );
}
entityManager.persist( hike );
return hike;
}
Emmanuel possible explanation:
here is my pseudo scientific proposal. In the code, we do a persist which triggers an insert request, then we add a link to the object which triggers an update request. Could it be that somehow, when the batch operation is happening, the two operations are 1. not collapsed 2. the second update is transformed into an insert. That would explain the behavior. Maybe that can lead you to an explanation of the bug.
|