You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Tim Holloway <ti...@mousetech.com> on 2008/06/18 23:26:47 UTC

OptimisticException on items without version info

I've been getting OptimisticExceptions merging on the following:

	@Transactional
	public Trips save(final Trips trip) {
		if (trip.getTripId() > 0) {
			log.warn("SAVE TRIPS *** BEGIN ***");
			final Trips trip1 = entityManager.merge(trip);
			log.warn("SAVE TRIPS *** END ***");
			return trip1;
		} else {
			entityManager.persist(trip);
			for (TripStops stop : trip.getTripStops()) {
				stop.setTrips(trip); // Affirm parent
				entityManager.persist(stop);
			}
			return trip;
		}
	}

Digging around in the debugger indicates that one of the children has a
NoneVersionStrategy, so attempts to compare versions will
unconditionally fail even between an object and itself. I was expecting
it to use the StateComparisonVersionStrategy, actually.

I know that Kodo would attempt to do a pessimistic update of changed
fields by making the WHERE clause of the update contain the expected
values of all item fields.

Of course, the bigger issue is that no fields are expected to have been
changed at all - the merge was supposed to be doing a re-attach.

So the question is, what am I doing wrong here?

For a complete set of class definitions, see the file uploaded under
Jira issue# OpenJPA-626. The offending item is the TripStops class after
making Fay's suggested corrections.