geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tomasz Mazan <win...@wp.pl>
Subject JPA - exception with Cascade Attach
Date Tue, 25 Sep 2007 10:12:34 GMT

I got three classes:

@Entity
@Table(name = "account") 
public class Account implements Serializable {

  @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy =
"account")
  private Set<Product> products = new HashSet<Product>();

...

}

@Entity
@Table(name = "product")
public class Product implements Serializable {

	@ManyToOne
	@JoinColumn(name = "acc_id", nullable = false)	
	private Account account;

	@OneToOne(mappedBy = "product", cascade = {CascadeType.ALL}, fetch =
FetchType.LAZY)
	private Config config;

..

}

@Entity
@Table(name = "config")
public class Config implements Serializable {

	@OneToOne(cascade={CascadeType.ALL}) // another version without cascade
	@JoinColumn(name = "prod_id", unique = true, nullable = true)
	private Product product;

...
}

In my code I'm creating new Product with subelement Config, and try to
persist using Account object.

Account acc = dao.getAccount... //persistent object
Product prod = new Product(); //creates new product with config
acc.addProduct(prod);
dao.updateAccount(acc);

and here I got exception :
<1.0.0-r561970-r561970 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: Encountered new object
"myapp.Product@1db71f1" in persistent field "myapp.Config.product" of
managed object "myapp.Config@1986e63" during attach.  However, this field
does not allow cascade attach.  You cannot attach a reference to a new
object without cascading.
FailedObject: myapp.Product@1db71f1
	at
org.apache.openjpa.kernel.AttachStrategy.getReference(AttachStrategy.java:276)
	at
org.apache.openjpa.kernel.AttachStrategy.attachField(AttachStrategy.java:193)
	at
org.apache.openjpa.kernel.VersionAttachStrategy.attach(VersionAttachStrategy.java:143)
	at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:241)
	at
org.apache.openjpa.kernel.AttachStrategy.attachField(AttachStrategy.java:201)
	at
org.apache.openjpa.kernel.VersionAttachStrategy.attach(VersionAttachStrategy.java:143)
	at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:241)
	at
org.apache.openjpa.kernel.AttachStrategy.attachCollection(AttachStrategy.java:330)
	at
org.apache.openjpa.kernel.DetachedStateManager.attach(DetachedStateManager.java:253)
	at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:241)
	at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:101)
	at org.apache.openjpa.kernel.BrokerImpl.attach(BrokerImpl.java:3186)
	at
org.apache.openjpa.kernel.DelegatingBroker.attach(DelegatingBroker.java:1147)
	at
org.apache.openjpa.persistence.EntityManagerImpl.merge(EntityManagerImpl.java:665)
	at
org.apache.geronimo.persistence.CMPEntityManagerTxScoped.merge(CMPEntityManagerTxScoped.java:97)
	at myapp.Dao.updateAccount(Dao.java:81)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:146)
	at
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:129)
	at
org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:67)
	at
org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:203)
	at
org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:165)
	at
org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:211)
	at
org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:65)
	at
org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:320)
	at
org.apache.openejb.util.proxy.Jdk13InvocationHandler.invoke(Jdk13InvocationHandler.java:49)
	at $Proxy94.update(Unknown Source)
	at ...

I've found similar cases using google, but I haven't found solution. Could
anyone help? 

tia
Beniamin

-- 
View this message in context: http://www.nabble.com/JPA---exception-with-Cascade-Attach-tf4514606s134.html#a12876660
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Mime
View raw message