[ 
https://issues.apache.org/jira/browse/OPENJPA-2335?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Mark Struberg reopened OPENJPA-2335:
------------------------------------

      Assignee: Pinaki Poddar

The change seems broken, it makes a few of my apps blow up.

I do not really get the whole change. The bug description doesn't tell me why 
this change got done and there is also no unit test for this change to tell me 
what you did like to fix. 

I can give you my use case which is now broken

Car -> n Inspections
with @OrderColumn(name = "POSITION")

Car c = new Car();
Inspection i1 = new Inspection(1, c); //Inspection adds itself to 
car.inspections
Inspection i2 = new Inspection(2, c);
em.persist(c).

This currently blurps out with 

Caused by: <openjpa-2.3.0-r422266:1538090M fatal user error> 
org.apache.openjpa.persistence.InvalidStateException: Attempt to set column 
"Inspection.POSITION" to two different values: (class java.lang.Integer)"1", 
(class java.lang.Integer)"0" This can occur when you fail to set both sides of 
a two-sided relation between objects, or when you map different fields to the 
same column, but you do not keep the values of these fields in synch.
        at org.apache.openjpa.jdbc.sql.PrimaryRow.setObject(PrimaryRow.java:344)
        at org.apache.openjpa.jdbc.sql.RowImpl.setInt(RowImpl.java:442)
        at 
org.apache.openjpa.jdbc.meta.strats.PrimitiveFieldStrategy.update(PrimitiveFieldStrategy.java:164)
        at 
org.apache.openjpa.jdbc.meta.strats.PrimitiveFieldStrategy.insert(PrimitiveFieldStrategy.java:124)
        at 
org.apache.openjpa.jdbc.meta.FieldMapping.insert(FieldMapping.java:623)
        at 
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.insert(AbstractUpdateManager.java:238)
        at 
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.populateRowManager(AbstractUpdateManager.java:165)
        at 
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:96)
        at 
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:77)


It seems that the @OrderColumn is the issue in this case. Your change looks 
fine for primary keys, but OrderColumns and all other stuff which gets 
auto-managed by OpenJPA also use the same code. 

Maybe we should only do these checks in case of real primary or foreign keys?



> Constrained foreign key column value setting needs to be flexible 
> ------------------------------------------------------------------
>
>                 Key: OPENJPA-2335
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2335
>             Project: OpenJPA
>          Issue Type: Bug
>            Reporter: Pinaki Poddar
>            Assignee: Pinaki Poddar
>             Fix For: 2.3.0
>
>
> Should allow setting a column from default value to a non-default value. The 
> logic had a bug.



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Reply via email to