Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Order of persit operations not preserved?
Order of persit operations not preserved? [message #389746] Fri, 26 June 2009 12:38 Go to next message
Torben Putkonen is currently offline Torben Putkonen
Messages: 34
Registered: July 2009
Member
have two tables:

Parent_table
PK
...

Child_table
...
FK (Parent_table)
...

I tried to do something like this:

parent.setPk("abc");
em.persist(parent);

child.setFk(parent.getPk());
em.persist(child);

When application server started to commit, EclipseLink executes first the
SQL insert for child which breaks due to a foreign key violation. Adding
an explicit call to flush() method fixed this issue:

parent.setPk("abc");
em.persist(parent);

em.flush();

child.setFk(parent.getPk());
em.persist(child);

Why doesn't this work without flush?

I'm using Oracle AS 10g, EclipseLink 1.1.1 and Oracle 11 with thin drivers.
Re: Order of persit operations not preserved? [message #389748 is a reply to message #389746] Fri, 26 June 2009 13:35 Go to previous messageGo to next message
Gordon Yorke is currently offline Gordon Yorke
Messages: 77
Registered: July 2009
Member
EclipseLink performs writes to the database based on constraint
dependencies interpreted from the relational mappings of an Entity. This
aleviates the need for users to managed operation ordering.

In your case, from the sample code, I suspect you have not actually mapped
this relationship but are managing the FKs yourself. In this case
EclipseLink does not have a mapping between these two Entities to
determine operation ordering. I recommend that you use a mapping here and
let EclipseLink manage the foreign keys for you.

If a mapping is not an option you can use a DescriptorCustomizer to add a
constraint dependency (ClassDescriptor.addConstraintDependency) between
the two Entity classes.

Otherwise continue to use the flush() api.
--Gordon
Re: Order of persit operations not preserved? [message #389749 is a reply to message #389748] Fri, 26 June 2009 14:12 Go to previous message
Torben Putkonen is currently offline Torben Putkonen
Messages: 34
Registered: July 2009
Member
I apologize, I forgot to include mappings to the pseudo code (yes, we had
those). I didn't have access to the source code when I sent the question,
but now I have and here is a more detailed example:

Table1:

@OneToMany(mappedBy = "table1", cascade = CascadeType.ALL)
private List<Table2> list;

Table2
@ManyToOne
@JoinColumn(name = "table1id", referencedColumnName = "table1id")
private Table1 table1;
Previous Topic:Generics and Eclipselink
Next Topic:transaction not commiting
Goto Forum:
  


Current Time: Fri Oct 31 18:43:39 GMT 2014

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

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