Phill,

This is what the spec says:

3.2.3 Synchronization to the Database

" For any entity Y referenced by a relationship from X, where the relationship to Y has not been annotated with the cascade element value cascade=PERSIST or cascade= ALL:
...
" If Y is detached, the semantics depend upon the ownership of the relationship. If X owns the relationship, any changes to the relationship are synchronized with the database; otherwise, if Y owns the relationships, the behavior is undefined.

HTH,
-marina

Phill Moran wrote:
That is my concern I should only have one copy of a storeType for many Store
entries. So if I add a record on the "one" side (Store) of a one-to-many"
relationship and have a relation set to an existing "Many" side (StoreType) I
don't want a new "Many" side record created as this would be a duplicate.

It seems unless I specify a cascade.Merge/Persist on the relationship field I
cannot persist a new Store with a relationship to a StoreType record even though
the StoreType record exists and does not need merging/persisting. What I am
looking to do is only persist data on the "one" side of the relationship and
never the "Many".
Make sense or just crazy coding?

Phill
-----Original Message-----
From: Marc Prud'hommeaux [mailto:[EMAIL PROTECTED] On Behalf Of Marc
Prud'hommeaux
Sent: April 24, 2007 2:23 PM
To: open-jpa-dev@incubator.apache.org
Subject: Re: Cascade question (ver 0.96)

Phill-


The behaviour I am looking for is simply persist the relation (i.e. the link field)


If you specify cascade=MERGE on the StoreType relation field, and you merge a
Store instance for which the StoreType relation doesn't already exists, does it
not persist the field as if it were new? That's the behavior I would expect...



On Apr 23, 2007, at 9:55 PM, Phill Moran wrote:


Here is a scenario that shows odd behaviour, I want to see if it is expected or not. The docs are not clear on it

If I have a many to one relationship for objects Store to Store Type and I create a new Store and assign it to an existing Store type does this relationship have to have cascasdeType.persist set when I issue a merge on the new Store? I had recently removed this as I thought I did not want to create a duplicate Store Type whenever I added a new Store. It seems OpenJPA throws the attached exception when I only have CascadeType.Refresh set. Alternatively, this could just be a poorly worded exception/ documentation meaning OpenJPA would check for the existence of this Store Type and not actually persist it if it exists. The behaviour I am looking for is simply persist the relation (i.e. the link field)

Thanks,
        Phill
<4|false|0.9.6-incubating>
org.apache.openjpa.persistence.ArgumentException:
Encountered new object
"ca.BidSpec.emall.categories.Category-105603b-508b-9c6-00f4-4031ba6429
e3:0" in
persistent field "ca.BidSpec.emall.stores.Store.type" of managed object "[EMAIL PROTECTED]" during attach. However, this field does not allow cascade attach. You cannot attach a reference to a new object without cascading.
FailedObject:
ca.BidSpec.emall.categories.Category-105603b-508b-9c6-00f4-4031ba6429e
3:0
        at
org.apache.openjpa.kernel.AttachStrategy.getReference
(AttachStrategy.java:272)
        at
org.apache.openjpa.kernel.AttachStrategy.attachField
(AttachStrategy.java:189)
        at
org.apache.openjpa.kernel.VersionAttachStrategy.attach
(VersionAttachStrategy.jav
a:130)
        at
org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:236)
        at org.apache.openjpa.kernel.AttachManager.attach
(AttachManager.java:97)
        at org.apache.openjpa.kernel.BrokerImpl.attach(BrokerImpl.java:3124)
        at
org.apache.openjpa.kernel.DelegatingBroker.attach
(DelegatingBroker.java:1120)
        at
org.apache.openjpa.persistence.EntityManagerImpl.merge
(EntityManagerImpl.java:59
1)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.jav
a:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
org.springframework.orm.jpa.ExtendedEntityManagerCreator
$ExtendedEntityManagerIn
vocationHandler.invoke(ExtendedEntityManagerCreator.java:283)
        at $Proxy37.merge(Unknown Source)
        at
ca.BidSpec.emall.persistence.JPAPersistenceFactory.merge
(JPAPersistenceFactory.j
ava:95)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.jav
a:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflectio
n(AopUtils
.java:304)
        at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke
(JdkDynamicAopProxy.j
ava:197)
        at $Proxy35.merge(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.jav
a:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflectio
n(AopUtils
.java:304)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoi
npoint(Ref
lectiveMethodInvocation.java:172)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed
(ReflectiveM
ethodInvocation.java:139)
        at
org.springframework.transaction.interceptor.TransactionInterceptor.inv
oke(Transa
ctionInterceptor.java:107)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed
(ReflectiveM
ethodInvocation.java:161)
        at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke
(JdkDynamicAopProxy.j
ava:203)
        at $Proxy35.merge(Unknown Source)
        at
ca.BidSpec.testing.emall.StoreFactoryTest.testSave
(StoreFactoryTest.java:69)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.jav
a:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at junit.framework.TestCase.runTest(TestCase.java:168)
        at junit.framework.TestCase.runBare(TestCase.java:134)
        at
org.springframework.test.ConditionalTestCase.runBare
(ConditionalTestCase.java:69
)
        at
org.springframework.test.annotation.AbstractAnnotationAwareTransaction
alTests.ac
cess$001(AbstractAnnotationAwareTransactionalTests.java:47)
        at
org.springframework.test.annotation.AbstractAnnotationAwareTransaction
alTests$1.
run(AbstractAnnotationAwareTransactionalTests.java:115)
        at
org.springframework.test.annotation.AbstractAnnotationAwareTransaction
alTests.ru
nTest(AbstractAnnotationAwareTransactionalTests.java:180)
        at
org.springframework.test.annotation.AbstractAnnotationAwareTransaction
alTests.ru
nTestTimed(AbstractAnnotationAwareTransactionalTests.java:153)
        at
org.springframework.test.annotation.AbstractAnnotationAwareTransaction
alTests.ru
nBare(AbstractAnnotationAwareTransactionalTests.java:111)
        at
org.springframework.test.jpa.AbstractJpaTests.runBare
(AbstractJpaTests.java:159)
        at
org.springframework.test.jpa.AbstractJpaTests.runBare
(AbstractJpaTests.java:239)
        at junit.framework.TestResult$1.protect(TestResult.java:110)
        at junit.framework.TestResult.runProtected(TestResult.java:128)
        at junit.framework.TestResult.run(TestResult.java:113)
        at junit.framework.TestCase.run(TestCase.java:124)
        at junit.framework.TestSuite.runTest(TestSuite.java:232)
        at junit.framework.TestSuite.run(TestSuite.java:227)
        at
org.junit.internal.runners.OldTestClassRunner.run
(OldTestClassRunner.java:35)
        at
org.junit.internal.runners.CompositeRunner.run(CompositeRunner.java: 29)
        at
org.junit.internal.runners.TestClassRunner$1.runUnprotected
(TestClassRunner.java
:42)
        at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected
(BeforeAndAfterRunne
r.java:34)
        at
org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java: 52)
        at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run
(JUnit4TestReferen
ce.java:38)
        at
org.eclipse.jdt.internal.junit.runner.TestExecution.run
(TestExecution.java:38)
        at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
(RemoteTestRunner
.java:460)
        at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
(RemoteTestRunner
.java:673)
        at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run
(RemoteTestRunner.java
:386)
        at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main
(RemoteTestRunner.jav
a:196)



Reply via email to