I have a following situation when I use OpenJPA
:
Those 3 entities: SelectQueryElement
, SingleSelectQueryElement
, CompositeQueryElement
are implemented thought SINGLE_TABLE
inheritance.
I also have ColumnClass
entity which holds top-level CompositeQueryElement
. Each of these classes have EAGER
loading and PERSIST
/MERGE
cascade type.
Now, if I want to mimic structure like this:
ColumnClass
| CompositeSelectQueryElement // top-level query element
| | SingleSelectQueryElement
| | CompositeSelectQueryElement
| | | SingleSelectQueryElement
| | SingleSelectQueryElement
| | CompositeSelectQueryElement
| | | SingleSelectQueryElement
... and I try to merge ColumnClass
object, I expect for insertion order to be "preorder". But what I get not even close to that.
I expected the following insertion order:
ColumnClass
1 | CompositeSelectQueryElement // TOP-LEVEL
2 | | SingleSelectQueryElement
3 | | CompositeSelectQueryElement
4 | | | SingleSelectQueryElement
5 | | SingleSelectQueryElement
6 | | CompositeSelectQueryElement
7 | | | SingleSelectQueryElement
OR at least:
ColumnClass
1 | CompositeSelectQueryElement // TOP-LEVEL
2 | | SingleSelectQueryElement
3 | | CompositeSelectQueryElement
6 | | | SingleSelectQueryElement
4 | | SingleSelectQueryElement
5 | | CompositeSelectQueryElement
7 | | | SingleSelectQueryElement
But what I got was this: (note that first come all Composite
s and after them all Single
s)
ColumnClass
1 | CompositeSelectQueryElement // TOP-LEVEL
4 | | SingleSelectQueryElement
2 | | CompositeSelectQueryElement
5 | | | SingleSelectQueryElement
6 | | SingleSelectQueryElement
3 | | CompositeSelectQueryElement
7 | | | SingleSelectQueryElement
Order of Single
s is not consistent either. Sometimes it's nothing like this but all random.
The question: is there any way to work around this ordering issue and "suggest" to OpenJPA
what I want to achieve.
I use OpenJPA v2.2.
This message from the OpenJPA mailing list seems to suggest your solution is to include <property name="openjpa.jdbc.UpdateManager" value="operation-order">
in your configuration. Hope that helps.