Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » v1.1+ attempts to INSERT a copy of unchanged data(Application persistence works fine up to 1.0.2, but strange behaviour in 1.1 and beyond)
v1.1+ attempts to INSERT a copy of unchanged data [message #488505] Tue, 29 September 2009 00:28 Go to next message
Brad Mising name is currently offline Brad Mising nameFriend
Messages: 21
Registered: September 2009
Junior Member
Entity Recording has a OneToOne mapping to Event (cascade ALL). Event has a ManyToOne mapping to Ownership. Ownership has a ManyToOne mapping to Aircraft (Cascade PERSIST).

In the current use case, the Recording, Event, Ownership, and Aircraft all exist in the database and are related as above. User specifies a different (but still existing) Ownership now to be associated with this Event. This changes the Aircraft also, as linked to Ownership. Once finished the transaction is committed.

This worked fine in EclipseLink 1.0.1 and 1.0.2.

But now in 1.1.0-.2, when updating the Ownership for an existing Event, I get a unique index violation, as it attempts to insert a new Ownership with exactly the same information as the existing one. Creating new Events (with existing Ownership and Aircraft) still works fine, as before.

Has there been an improvement that has uncovered a design flaw in my code, or is there a regression in v1.1?

Many thanks
Brad
Re: v1.1+ attempts to INSERT a copy of unchanged data [message #489089 is a reply to message #488505] Thu, 01 October 2009 13:33 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Could you include the sample code that causes your error.

For the new Ownership, how is this created? Is it read from the same EntityManager as the Event and commit, or was it read using a different EntityManager, or in a different transaction? Try doing a find() first for the Ownership to get the correct object for the persistence context.



James : Wiki : Book : Blog : Twitter
Re: v1.1+ attempts to INSERT a copy of unchanged data [message #489180 is a reply to message #489089] Thu, 01 October 2009 17:51 Go to previous messageGo to next message
Brad Mising name is currently offline Brad Mising nameFriend
Messages: 21
Registered: September 2009
Junior Member
It all uses the same entity manager instance. The Ownership isn't new, it is retrieved from a query, as is the Recordings, and Aircraft. The new Event is created just using new Event(), then the setRecording(..) and setOwnership(..) are called on Event. The transaction is then committed.

Relevant sections of code are (paraphrased):

List<Recording> recordings = entityManager.createQuery("SELECT r FROM Recording r ORDER BY r.date, r.time").getResultList();
List<Ownership> ownerships = entityManager.createQuery("SELECT o FROM Ownership o WHERE o.effectiveDate <= :thisDate AND (o.ineffectiveDate >= :thisDate OR o.ineffectiveDate IS null) ORDER BY o.registration").getResultList();


In Event.java:
@JoinColumn(name = "ownership_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private Ownership ownership;
@JoinColumn(name = "recording_id", referencedColumnName = "id")
@OneToOne(optional = false)
private Recording recording;
...

In Ownership.java:
@JoinColumn(name = "aircraft_id", referencedColumnName = "id")
@ManyToOne(optional = false, cascade = CascadeType.PERSIST)
private Aircraft aircraft;

In Recording.java:
@OneToOne(mappedBy = "recording", cascade = CascadeType.ALL)
private Event event;


Then when the user chooses to submit any changes:
currentRecording.setEvent(this.currentEvent);
this.currentEvent.setOwnership(currentOwnership);
...
EntityTransaction transaction = this.entityManager.getTransaction();
transaction.commit();


The code itself is pretty straightforward, and JSR295 is actually used to tie the interface to the entities. And as I said, works perfectly in 1.0.2.

Thanks for your help

[Updated on: Thu, 01 October 2009 17:53]

Report message to a moderator

Re: v1.1+ attempts to INSERT a copy of unchanged data [message #489648 is a reply to message #488505] Mon, 05 October 2009 13:30 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

I can't see how this could occur. Nothing looks incorrect in how you have described your code.

You may wish to try the latest 1.1 build, or the 1.2 or 2.0 builds to see if the issue still occurs.

You could also try setting logging to finest to see if anything odd is logged. You could also try a flush or commit after each operation to narrow down where the issue occurs.

If you can isolate a simple test case that demonstrates the issue you could log a bug. Or if you have a support contract, you could contact Oracle technical support.


James : Wiki : Book : Blog : Twitter
Previous Topic:Using @ManyToOne with a @JoinTable
Next Topic:SQLResultSetMapping - aliases in NativeQuery not working
Goto Forum:
  


Current Time: Tue Mar 19 07:08:02 GMT 2024

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

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

Back to the top