Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » Validation exception on spurious insert during a query transaction(Confusing insert during a transaction that simply loads and returns an object.)
Validation exception on spurious insert during a query transaction [message #1062087] Wed, 05 June 2013 16:12 Go to next message
Eclipse UserFriend
Hi,

I'm pretty new to Eclipse Link, and I'm very confused by some of the behavior.

I'm using EL with Postgres, and Spring transactions. Here's a simplified version of my code:

1. The entity model

entity A
basic id
one-to-many B myBs

entity B
basic id

2. The sequence that succeeds

A myA = new A();

TransactionAction ta = new TransactionAction() {
public void doTransaction() {
em.persist(myA);
}
};

TransactinAction ta2 = new TransactionAction() {
public A doTransaction() {
String query = "select a from A a";
Query q = em.createQuery(query);
List list = q.getResultList();
return (A) list.get(0);
}
};

executeTransaction(ta);

A fromDB = executeTransaction(ta2);

3. The sequence that fails

If I do exactly the sequence above, but the "myA" object has an instance of B inside it. When I do that, I see an attempt to re-insert the instance of A when ta2 commits.

I'm very confused as to why, in a transaction that has simply loaded an object, there is an attempt to persist it at all. Notice that none of the code of ta2 does anything to persist the object, it's just loaded and returned.

Any help would be much appreciated!
Re: Validation exception on spurious insert during a query transaction [message #1062256 is a reply to message #1062087] Thu, 06 June 2013 14:26 Go to previous message
Eclipse UserFriend
How have you defined the A->B relationship, and is B inserted correctly or does it represent an existing entity? Is there a back reference from B to A? Do you set the id value or does it get generated through sequencing?

[Updated on: Thu, 06 June 2013 14:29] by Moderator

Previous Topic:OnetoOne mapping issue
Next Topic:Determine 'create' or 'update' Entity
Goto Forum:
  


Current Time: Mon May 12 18:28:01 EDT 2025

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

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

Back to the top