Hi, The openjpa.UpdateManager configuration property can be used to control the order that SQL statements are executed. There are really two options for this property, OperationOrder and Constraint. These options are further separated by whether they support SQL batching - so there's also a BatchingOperationOrder and BatchingConstraint. The batching variations do not change the order of SQL though - they just submit batch operations when possible.
The OperationOrder update manager (and BatchingOperationOrder) execute SQL statements in the same order that the application calls em.persist, em.merge, em.remove, and so on. So if you use the OperationOrder update manager you can ensure A gets inserted first by calling em.persist(A), and then do whatever other work you want to do. The Constraint update manager (and BatchingConstraint) may reorder the SQL operations (at commit / flush time) to ensure any FK constraints are honored. The catch here is that OpenJPA can only reorder for the constraints it knows about. By default OpenJPA does not assume that there is a ForiegnKey constraint but you can use the @ForeignKey to tell OpenJPA that there is a constraint. So, the short answer is that you probably want to use the OperationOrder or BatchingOperationOrder update manager. Just add this to persistence.xml : <property name="openjpa.UpdateManager" value="batching-operation-order"/> Alternatively if you have ForeignKeys in your database then you could use @ForeignKey and OpenJPA will reorder the SQL 'automatically'. HTH, -mike On Sat, May 1, 2010 at 1:59 PM, JayaPrakash <[email protected]> wrote: > > Hi All, > > In an Object tree, is there a way I can force a particular object to > be always inserted/updated first during persist/merge operation? > > For example in an object tree like A -> B -> C -> D, and B, C and D have > their corresponding children. In this scenario I want always the A objects > Inserts/Updates to happen first. I dont really care how what order is > followed after that. > > Thanks, > JP > > -- > View this message in context: > http://openjpa.208410.n2.nabble.com/Forcing-an-Object-to-be-always-inserted-updated-first-during-persist-merge-tp4990960p4990960.html > Sent from the OpenJPA Users mailing list archive at Nabble.com. >
