Java Mailing List Archive

http://www.gg3721.com/

Home » users.openjpa »

@PrePersist callback and merge/persist behaviour

g.chauvet

2013-06-11


Author LoginPost Reply

Dear OpenJPA users,

 

We have a problem with merging some detached entities in the below  usecase :

 

Initial state:
==========
The data base already contains an entities tree depth level 3 organized as follows:
* 1 instance of type "TreeRoot" type : A1
* 1 instance of "TreeLevelOne" type : B1
* 1 instance of "ConcreteTreeLeaf" type : C1
 
-> Representation of the entity linking 
A1 -> [B1 -> [C1]]

 

Scenario:
=================
1) Detach entity A1 and these children (with a FetchPlan)

                * State of the graph following detach operation:

A1 -> [B1 -> [C1]]

2) Add a new instance of ConceteTreeLeaf "C4" type into entity B1:
                * State of the graph following insertion:
                               A1 -> [B1 -> [C1, C4]]

3) Merge and Persist entity « A1 » throw this exceptions :

<openjpa-2.2.3-SNAPSHOT-r422266:1485013M fatal user error> org.apache.openjpa.persistence.InvalidStateException: The field "level" of instance "com.qualiformed.openjpa.issue.entity.ConcreteTreeLeaf@6290ebfe" contained a null value; the metadata for this field specifies that nulls are illegal.

But if I perform merge operation only, the @PrePersist callback on my new Entity « C4 » is not fired and I obtain this another kind of exception :

 

Caused by: <openjpa-2.2.3-SNAPSHOT-r422266:1485013M fatal general error> org.apache.openjpa.persistence.PersistenceException: Column 'ID'  cannot accept a NULL value. {prepstmnt 566695176 INSERT INTO APP.TreeLeaf (LEVEL_ID, CONCRETE_ORDER) VALUES (?, ?)} [code=20000, state=23502]

 

Attached please, a small unitary test that reproduce the explained behaviour.

 

Best regards,

Guillaume


Attachment: MergePersistCallback.zip (zipped)
©2008 gg3721.com - Jax Systems, LLC, U.S.A.