I think maybe the issue is a simple usage issue.

If you already have a persistent StoreType instance, and you store a reference to it in a new Store instance, then when you persist the Store, the StoreType instance is simply used to provide a foreign key in the database.

And if you have a detached Store instance and set the relationship to a detached StoreType instance, when you merge, the StoreType is again used as a reference to provide the foreign key.

Are you using a persistent or detached StoreType as the reference in your Store? Because if you're using a new StoreType instance and there is already an instance of StoreType in the database, you will get an error.

Craig

On Apr 24, 2007, at 11:53 AM, 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-4031ba642 9
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-4031ba6429 e
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.invokeJoinpointUsingReflecti o
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.invokeJoinpointUsingReflecti o
n(AopUtils
.java:304)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJo i
npoint(Ref
lectiveMethodInvocation.java:172)
        at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed
(ReflectiveM
ethodInvocation.java:139)
        at
org.springframework.transaction.interceptor.TransactionInterceptor.in v
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.AbstractAnnotationAwareTransactio n
alTests.ac
cess$001(AbstractAnnotationAwareTransactionalTests.java:47)
        at
org.springframework.test.annotation.AbstractAnnotationAwareTransactio n
alTests$1.
run(AbstractAnnotationAwareTransactionalTests.java:115)
        at
org.springframework.test.annotation.AbstractAnnotationAwareTransactio n
alTests.ru
nTest(AbstractAnnotationAwareTransactionalTests.java:180)
        at
org.springframework.test.annotation.AbstractAnnotationAwareTransactio n
alTests.ru
nTestTimed(AbstractAnnotationAwareTransactionalTests.java:153)
        at
org.springframework.test.annotation.AbstractAnnotationAwareTransactio n
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)



Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:[EMAIL PROTECTED]
P.S. A good JDO? O, Gasp!

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to