Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 20:12 Go to next message
Jon Whitney is currently offline Jon WhitneyFriend
Messages: 1
Registered: June 2013
Junior Member
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 18:26 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1039
Registered: July 2009
Senior Member
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 18:29]

Report message to a moderator

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


Current Time: Fri Dec 19 10:21:06 GMT 2014

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

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