openjpa-dev mailing list archives

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


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

Person p1 = em.find(Person.class, new Long(1));
Address a = p1.getAddresses.remove(0);
Person p2 = new Person();

Currently it throws:

2234  default  TRACE  [main] openjpa.jdbc.SQL - <t 13101223, conn 12437939> executing
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)
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(
	at org.apache.openjpa.kernel.BrokerImpl.flush(
	at org.apache.openjpa.kernel.BrokerImpl.flushSafe(
	at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(
	at org.apache.openjpa.kernel.LocalManagedRuntime.commit(
	at org.apache.openjpa.kernel.BrokerImpl.commit(
	at org.apache.openjpa.kernel.DelegatingBroker.commit(
	at org.apache.openjpa.persistence.EntityManagerImpl.commit(
	at oopex.openjpa2.jpa2.relationships.OneToManyUnidirectionalJoinColumnMain.shuffle(
	at oopex.openjpa2.jpa2.relationships.OneToManyUnidirectionalJoinColumnMain.main(
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(
	at org.apache.openjpa.jdbc.sql.RowImpl.flushJoinValues(
	at org.apache.openjpa.jdbc.sql.RowImpl.flushForeignKey(
	at org.apache.openjpa.jdbc.sql.RowImpl.setForeignKey(
	at org.apache.openjpa.jdbc.sql.PrimaryRow.setForeignKey(
	at org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.updateInverse(
	at org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.insert(
	at org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.insert(
	at org.apache.openjpa.jdbc.meta.FieldMapping.insert(
	at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.insert(
	at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.populateRowManager(
	at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(
	at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(
	at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(
	at org.apache.openjpa.kernel.DelegatingStoreManager.flush(
	... 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:
>             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.

View raw message