openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pinaki Poddar (JIRA)" <j...@apache.org>
Subject [jira] Commented: (OPENJPA-1255) InvalidStateException when using @MappedById and @JoinColumn on a unidirectional @ManyToOne relationship
Date Thu, 27 Aug 2009 22:06:59 GMT

    [ https://issues.apache.org/jira/browse/OPENJPA-1255?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12748590#action_12748590
] 

Pinaki Poddar commented on OPENJPA-1255:
----------------------------------------

E1 is effectively using a composite primary key. This composite key of E1 is combination of
E1.id and primary key of E2.
According to JPA spec 2.0 (section 2.4) : "A primary key class must be defined to represent
a composite primary key."

> InvalidStateException when using @MappedById and @JoinColumn on a unidirectional @ManyToOne
relationship
> --------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-1255
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1255
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jdbc
>            Reporter: Rick Curtis
>
> I found that if I have a ManyToOne relationship using the JoinColumn and MappedById annotations
I receive the following exception:
> <openjpa-2.0.0-SNAPSHOT-r422266:804085M fatal store error> org.apache.openjpa.util.StoreException:
The transaction has been rolled back.  See the nested exceptions for details on the errors
that occurred.
> 	at org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2292)
> 	at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2140)
> .....
> 	at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:553)
> 	at main.Driver.main(Driver.java:67)
> Caused by: <openjpa-2.0.0-SNAPSHOT-r422266:804085M fatal user error> org.apache.openjpa.util.InvalidStateException:
Attempt to set column "E1.id" to two different values: (class java.lang.Integer)"1", (class
java.lang.Integer)"2" 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:437)
> 	at org.apache.openjpa.jdbc.meta.strats.PrimitiveFieldStrategy.update(PrimitiveFieldStrategy.java:159)
> 	at org.apache.openjpa.jdbc.meta.strats.PrimitiveFieldStrategy.insert(PrimitiveFieldStrategy.java:119)
> 	at org.apache.openjpa.jdbc.meta.FieldMapping.insert(FieldMapping.java:608)
> 	at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.insert(AbstractUpdateManager.java:230)
> 	at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.populateRowManager(AbstractUpdateManager.java:162)
> 	at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:95)
> 	at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:76)
> 	at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:675)
> 	at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
> 	... 8 more
> I created this problem by running the following code in a JSE environment:
>       em.getTransaction().begin();
>       E2 e2 = new E2(1);
>       em.persist(e2);
>       em.persist(new E1(e2,2));
>       em.persist(new E1(e2,3));
>       em.getTransaction().commit();
> The domain model is as follows:
> @Entity
> public class E1 {
>     @Id
>     private int id;
>     @ManyToOne(cascade = CascadeType.PERSIST)
>     @MappedById
>     @JoinColumn(name = "something_fk")
>     private E2 e2;
>     public E1(E2 e, int i) {
>         e2 = e;
>         id = i;
>     }
>     public E1() {
>     }
> }//end E1
> @Entity
> public class E2 {
>     @Id
>     private int id;
>     public E2(int i) {
>         id = i;
>     }
>     public E2() {
>     }
> }// end E2

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message