openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Nelson" <eric.nel...@unishippers.com>
Subject RE: Problem with foreign keys on DB and JPA delete
Date Wed, 02 Jul 2008 13:59:48 GMT
Hi Beniamin.  Two things to try:

1. Add CascadeType.REMOVE to your SubProduct annotation
2. Add @ForeignKey annotation to SubProduct just after the @JoinColumn
annotation.  We ran into an issue where OpenJPA was trying to delete the
table that was referenced by the foreign key before deleting the table
with the foreign key, which obviously violates DB deletion rules.
Adding @ForeignKey forced it to delete the rows in proper order.  Hope
this helps.

--Eric

-----Original Message-----
From: Beniamin Mazan [mailto:it@mazan.pl] 
Sent: Tuesday, July 01, 2008 6:01 PM
To: users@openjpa.apache.org
Subject: Problem with foreign keys on DB and JPA delete


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.flushInterna
l(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(QueryExecu
torImpl.java:1548)
	at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImp
l.java:1316)
	at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:
191)
	at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Stateme
nt.java:452)
	at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdb
c2Statement.java:351)
	at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2S
tatement.java:305)
	at sun.reflect.GeneratedMethodAccessor597.invoke(Unknown Source)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.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(Prepared
StatementHandle.java:103)
	at
org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(De
legatingPreparedStatement.java:269)
	at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection
$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:
856)
	at
org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(De
legatingPreparedStatement.java:269)
	at
org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(De
legatingPreparedStatement.java:269)
	at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.
executeUpdate(JDBCStoreManager.java:1363)
	at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInterna
l(PreparedStatementManagerImpl.java:97)
	at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(Prepar
edStatementManagerImpl.java:73)
	at
org.apache.openjpa.jdbc.kernel.OperationOrderUpdateManager.flushPrimaryR
ow(OperationOrderUpdateManager.java:162)
	at
org.apache.openjpa.jdbc.kernel.OperationOrderUpdateManager.flush(Operati
onOrderUpdateManager.java:89)
	at
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdat
eManager.java:89)
	at
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdat
eManager.java:72)
	at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.j
ava:514)
	at
org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreMa
nager.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:17
70)
	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(Tr
ansactionImpl.java:400)
	at
org.apache.geronimo.transaction.manager.TransactionImpl.commit(Transacti
onImpl.java:257)
	at
org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit(Tr
ansactionManagerImpl.java:245)
	at
org.apache.openejb.core.transaction.TransactionPolicy.commitTransaction(
TransactionPolicy.java:141)
	at
org.apache.openejb.core.transaction.TxRequiresNew.afterInvoke(TxRequires
New.java:72)
	at
org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessCo
ntainer.java:233)
	at
org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessCo
ntainer.java:188)
	at
org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessCon
tainer.java:165)
	at
org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObje
ctProxyHandler.java:217)
	at
org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxy
Handler.java:77)
	at
org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandl
er.java:321)
	at
org.apache.openejb.util.proxy.Jdk13InvocationHandler.invoke(Jdk13Invocat
ionHandler.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.jav
a:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocati
on.invoke(ReflectionInvocationContext.java:146)
	at
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(
ReflectionInvocationContext.java:129)
	at
org.apache.geronimo.cxf.ejb.EJBMethodInvoker.directEjbInvoke(EJBMethodIn
voker.java:156)
	at
org.apache.geronimo.cxf.ejb.EJBMethodInvoker.ejbInvoke(EJBMethodInvoker.
java:119)
	at
org.apache.geronimo.cxf.ejb.EJBMethodInvoker.invoke(EJBMethodInvoker.jav
a:72)
	at
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.ja
va:63)
	at
org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvoke
rInterceptor.java:56)
	at
org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(Servi
ceInvokerInterceptor.java:89)
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC
hain.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.jav
a:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocati
on.invoke(ReflectionInvocationContext.java:146)
	at
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(
ReflectionInvocationContext.java:129)
	at
org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorS
tack.java:73)
	at
org.apache.openejb.core.stateless.StatelessContainer.invokeWebService(St
atelessContainer.java:277)
	at
org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessCo
ntainer.java:206)
	at
org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessCo
ntainer.java:188)
	at
org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessCon
tainer.java:165)
	at
org.apache.geronimo.cxf.ejb.EJBMethodInvoker.preEjbInvoke(EJBMethodInvok
er.java:94)
	at
org.apache.geronimo.cxf.ejb.EJBMethodInvoker.invoke(EJBMethodInvoker.jav
a:69)
	at
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.ja
va:63)
	at
org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvoke
rInterceptor.java:56)
	at
org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor
.java:37)
	at
org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(Servi
ceInvokerInterceptor.java:92)
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC
hain.java:207)
	at
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiati
onObserver.java:73)
	at
org.apache.geronimo.cxf.GeronimoDestination.invoke(GeronimoDestination.j
ava:115)
	at
org.apache.geronimo.cxf.CXFWebServiceContainer.processPOST(CXFWebService
Container.java:107)
	at
org.apache.geronimo.cxf.CXFWebServiceContainer.invoke(CXFWebServiceConta
iner.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:2
63)
	at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:84
4)
	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-tp1
8227738p18227738.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message