openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fay Wang <fyw...@yahoo.com>
Subject Re: Problem with foreign keys on DB and JPA delete
Date Thu, 03 Jul 2008 16:11:06 GMT
Hi,
    From the stack trace:
...
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:73)
    at
org.apache.openjpa.jdbc.kernel.OperationOrderUpdateManager.flushPrimaryRow(OperationOrderUpdateManager.java:162)
    at
org.apache.openjpa.jdbc.kernel.OperationOrderUpdateManager.flush(OperationOrderUpdateManager.java:89)

...

   it appears that you are using OperationOrderUpdateManager. My understanding is that for
OperationOrderUpdateManager, application is responsible for the ordering of the delete operations.
You might want to try ConstraintUpdateManager to see if it fixes your problem.

-fay


--- On Tue, 7/1/08, Beniamin Mazan <it@mazan.pl> wrote:

> From: Beniamin Mazan <it@mazan.pl>
> Subject: Problem with foreign keys on DB and JPA delete
> To: users@openjpa.apache.org
> Date: Tuesday, July 1, 2008, 5:01 PM
> I got 
> foreign key on delete cascade constraint on my database for
> relation between
> Product and Subproduct
> 
> CREATE TABLE product (
>     id character varying(36) PRIMARY KEY,
>     ...
> );
> 
> CREATE TABLE voice_mail (
>     id character varying(36) PRIMARY KEY,
>     flag_attribure boolean NOT NULL,
>     .....
>     phone_id character varying(255) UNIQUE,
>     FOREIGN KEY (phone_id) REFERENCES phone(id) ON UPDATE
> CASCADE ON DELETE
> CASCADE
> );
> 
> My Entities are in relation declared as:
> 
> Within Product class
> @OneToOne(cascade = CascadeType.ALL, fetch =
> FetchType.EAGER, mappedBy =
> "product")
> 
> and within Subproduct class
> @OneToOne(cascade = {CascadeType.MERGE,
> CascadeType.REFRESH}, fetch =
> FetchType.EAGER)
> @JoinColumn(name = "product_id", unique = true,
> nullable = true)
> 
> 
> and persistence.xml properties
> 		<properties>
> 			<property name="openjpa.Sequence"
> value="class-table(Table=_SEQ_GENERATOR,
> UseAliases=true)"/>
>  			<property
> name="openjpa.jdbc.SynchronizeMappings"
> value="buildSchema(SchemaAction=refresh)" />
>  			<property name="openjpa.jdbc.DBDictionary"
> value="postgres"/>
>  			<property name="openjpa.Multithreaded"
> value="true" />
>             <property
> name="openjpa.TransactionMode"
> value="managed" />
>             <property
> name="openjpa.AutoDetach"
> value="commit" />
>             <property
> name="openjpa.RestoreState" value="all"
> /> 		
>             <property
> name="openjpa.Optimistic"
> value="true"/>		
> 		</properties>
> 
> 1. I got OptimistickLockException when I try to delete
> object of Product
> class. It tells that Subproduct was modified.
> 2. Using <property
> name="openjpa.jdbc.SchemaFactory"
> value="native(ForeignKeys=true)"/>  does not
> change anything 
> 3. Using <property
> name="openjpa.jdbc.MappingDefaults"
> value="ForeignKeyDeleteAction=restrict,
> JoinForeignKeyDeleteAction=restrict"/> changes
> stacktrace to:
> 
> 	at
> org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeUpdate(JDBCStoreManager.java:1363)
> 	at
> org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:97)
> 	... 72 more
> NestedThrowables:
> org.postgresql.util.PSQLException: ERROR: current
> transaction is aborted,
> commands ignored until end of transaction block
> 	at
> org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1548)
> 	at
> org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1316)
> 	at
> org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:191)
> 	at
> org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452)
> 	at
> org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:351)
> 	at
> org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:305)
> 	at sun.reflect.GeneratedMethodAccessor597.invoke(Unknown
> Source)
> 	at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at
> org.postgresql.ds.jdbc23.AbstractJdbc23PooledConnection$StatementHandler.invoke(AbstractJdbc23PooledConnection.java:471)
> 	at $Proxy341.executeUpdate(Unknown Source)
> 	at
> org.tranql.connector.jdbc.PreparedStatementHandle.executeUpdate(PreparedStatementHandle.java:103)
> 	at
> org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:269)
> 	at
> org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:856)
> 	at
> org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:269)
> 	at
> org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:269)
> 	at
> org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeUpdate(JDBCStoreManager.java:1363)
> 	at
> org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:97)
> 	at
> org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:73)
> 	at
> org.apache.openjpa.jdbc.kernel.OperationOrderUpdateManager.flushPrimaryRow(OperationOrderUpdateManager.java:162)
> 	at
> org.apache.openjpa.jdbc.kernel.OperationOrderUpdateManager.flush(OperationOrderUpdateManager.java:89)
> 	at
> org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:89)
> 	at
> org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:72)
> 	at
> org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:514)
> 	at
> org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
> 	at
> org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1954)
> 	at
> org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1852)
> 	at
> org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1770)
> 	at
> org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:514)
> 	at
> org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:499)
> 	at
> org.apache.geronimo.transaction.manager.TransactionImpl.beforePrepare(TransactionImpl.java:400)
> 	at
> org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:257)
> 	at
> org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit(TransactionManagerImpl.java:245)
> 	at
> org.apache.openejb.core.transaction.TransactionPolicy.commitTransaction(TransactionPolicy.java:141)
> 	at
> org.apache.openejb.core.transaction.TxRequiresNew.afterInvoke(TxRequiresNew.java:72)
> 	at
> org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:233)
> 	at
> org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:188)
> 	at
> org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:165)
> 	at
> org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:217)
> 	at
> org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:77)
> 	at
> org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:321)
> 	at
> org.apache.openejb.util.proxy.Jdk13InvocationHandler.invoke(Jdk13InvocationHandler.java:49)
> 	at $Proxy315.deleteVoice(Unknown Source)
> 	at myApp.myCore.deleteVoiceNrn(myCore.java:548)
> 	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:597)
> 	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.geronimo.cxf.ejb.EJBMethodInvoker.directEjbInvoke(EJBMethodInvoker.java:156)
> 	at
> org.apache.geronimo.cxf.ejb.EJBMethodInvoker.ejbInvoke(EJBMethodInvoker.java:119)
> 	at
> org.apache.geronimo.cxf.ejb.EJBMethodInvoker.invoke(EJBMethodInvoker.java:72)
> 	at
> org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:63)
> 	at
> org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:56)
> 	at
> org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:89)
> 	at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:207)
> 	at
> org.apache.geronimo.cxf.ejb.EJBInterceptor.intercept(EJBInterceptor.java:148)
> 	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:597)
> 	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:73)
> 	at
> org.apache.openejb.core.stateless.StatelessContainer.invokeWebService(StatelessContainer.java:277)
> 	at
> org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:206)
> 	at
> org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:188)
> 	at
> org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:165)
> 	at
> org.apache.geronimo.cxf.ejb.EJBMethodInvoker.preEjbInvoke(EJBMethodInvoker.java:94)
> 	at
> org.apache.geronimo.cxf.ejb.EJBMethodInvoker.invoke(EJBMethodInvoker.java:69)
> 	at
> org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:63)
> 	at
> org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:56)
> 	at
> org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
> 	at
> org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:92)
> 	at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:207)
> 	at
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:73)
> 	at
> org.apache.geronimo.cxf.GeronimoDestination.invoke(GeronimoDestination.java:115)
> 	at
> org.apache.geronimo.cxf.CXFWebServiceContainer.processPOST(CXFWebServiceContainer.java:107)
> 	at
> org.apache.geronimo.cxf.CXFWebServiceContainer.invoke(CXFWebServiceContainer.java:83)
> 	at
> org.apache.geronimo.tomcat.TomcatEJBWebServiceContext$EJBWebServiceValve.invoke(TomcatEJBWebServiceContext.java:180)
> 	at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
> 	at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
> 	at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
> 	at
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
> 	at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
> 	at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
> 	at
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
> 	at
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
> 		
> 
> I don't know what to do. 
> Thanks in advance
> 
> -----
> thanks
> Beniamin
> -- 
> View this message in context:
> http://www.nabble.com/Problem-with-foreign-keys-on-DB-and-JPA-delete-tp18227738p18227738.html
> Sent from the OpenJPA Users mailing list archive at
> Nabble.com.


      

Mime
View raw message