openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Frank Schwarz (JIRA)" <j...@apache.org>
Subject [jira] Commented: (OPENJPA-1253) JoinColumn annotation not allowed in conjunction with *ToMany annotation
Date Sat, 19 Sep 2009 16:15:16 GMT

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

Frank Schwarz commented on OPENJPA-1253:
----------------------------------------

> Create/Update/Delete/Find for the non-default OneToMany

Please also consider this use case:

Model: Person --> * Address (unidirectional, one-to-many, join-column)
public class Person {
	@OneToMany(cascade = CascadeType.ALL)
	@JoinColumn(name = "PERSON_ID")
	private List<Address> addresses = new ...
}

Use-case:
Person p1 = em.find(Person.class, new Long(1));
Address a = p1.getAddresses.remove(0);
Person p2 = new Person();
p2.getAddresses().add(a);
em.persist(p2)


Currently it throws:

2234  default  TRACE  [main] openjpa.jdbc.SQL - <t 13101223, conn 12437939> executing
prepstmnt 32053837 SELECT TEST.PERSON_SEQ.NEXTVAL FROM DUAL
2235  default  TRACE  [main] openjpa.jdbc.SQL - <t 13101223, conn 12437939> [0 ms] spent
2341  default  TRACE  [main] openjpa.jdbc.SQL - <t 13101223, conn 19396509> executing
prepstmnt 620055 UPDATE TEST.Address SET PERSON_ID = ? WHERE id = ? [params=(null) null, (long)
2]
2342  default  TRACE  [main] openjpa.jdbc.SQL - <t 13101223, conn 19396509> [1 ms] spent
2342  default  TRACE  [main] openjpa.Runtime - An exception occurred while ending the transaction.
 This exception will be re-thrown.
<openjpa-2.0.0-SNAPSHOT-r422266:816795 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:2249)
	at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2096)
	at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1994)
	at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1912)
	at org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime.java:81)
	at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1436)
	at org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:895)
	at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:557)
	at oopex.openjpa2.jpa2.relationships.OneToManyUnidirectionalJoinColumnMain.shuffle(OneToManyUnidirectionalJoinColumnMain.java:157)
	at oopex.openjpa2.jpa2.relationships.OneToManyUnidirectionalJoinColumnMain.main(OneToManyUnidirectionalJoinColumnMain.java:59)
Caused by: <openjpa-2.0.0-SNAPSHOT-r422266:816795 fatal user error> org.apache.openjpa.util.InvalidStateException:
Attempt to set column "Address.PERSON_ID" to two different values: (null)"null", (class java.lang.Long)"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.flushJoinValues(RowImpl.java:289)
	at org.apache.openjpa.jdbc.sql.RowImpl.flushForeignKey(RowImpl.java:222)
	at org.apache.openjpa.jdbc.sql.RowImpl.setForeignKey(RowImpl.java:197)
	at org.apache.openjpa.jdbc.sql.PrimaryRow.setForeignKey(PrimaryRow.java:172)
	at org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.updateInverse(RelationToManyInverseKeyFieldStrategy.java:334)
	at org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.insert(RelationToManyInverseKeyFieldStrategy.java:204)
	at org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.insert(RelationToManyInverseKeyFieldStrategy.java:190)
	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:677)
	at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
	... 9 more


Persisting the p2-object before transferring the address-object or issuing a em.flush() before
transferring the address-object will not bring up the error.

> JoinColumn annotation not allowed in conjunction with *ToMany annotation
> ------------------------------------------------------------------------
>
>                 Key: OPENJPA-1253
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1253
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jdbc
>    Affects Versions: 2.0.0-M1, 2.0.0-M2, 2.0.0-M3, 2.0.0-M4, 2.0.0
>            Reporter: Rick Curtis
>             Fix For: 2.0.0
>
>
> I receive the following exception if I have an Entity with a One(Many)ToMany relationship
with another Entity. 
> <openjpa-2.0.0-SNAPSHOT-r422266:805588 fatal user error> org.apache.openjpa.persistence.ArgumentException:
You have supplied columns for "....Entity", but this mapping cannot have columns in this context.
> To recreate the failure, add a @JoinColumn annotation to one of the *ToMany relationships
in org.apache.openjpa.persistence.jdbc.annotations.AnnoTest1. 
> example:
>     @MapKey(name = "basic")
>     @OneToMany(mappedBy = "oneManyOwner")
>     @JoinColumn(name = "asdf")
>     protected Map<String, AnnoTest2> inverseOwnerMapKey = new HashMap();
> Then run:
> trunk\openjpa-parent\openjpa-persistence-jdbc>mvn test -Dtest=org.apache.openjpa.persistence.jdbc.annotations.TestOneToMany

-- 
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