EJB persistence in incorrect order
lduperval May 23, 2005 3:15 PMHello,
I am trying to figure out a problem with my JBoss installation. I have a number of 1-M relationships defined and when I try to create data that contains a foreign key, I always get errors like this:
java.sql.SQLException: INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'SM_FOREIGN_KEY'. The conflict occurred in database 'TE', table 'MEMO', column 'MEMO_UUID'. at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:364) at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2708) at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2150) at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:587) at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:438) at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:421) at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:397) at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:335) at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.executeInsert(JDBCAbstractCreateCommand.java:328) at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.performInsert(JDBCAbstractCreateCommand.java:286) at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.execute(JDBCAbstractCreateCommand.java:137) at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:562) at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:203) at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.java:269) at org.jboss.ejb.EntityContainer.createLocalHome(EntityContainer.java:576) 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:324) at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:1061) at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:88) at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:204) at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnectionInterceptor.java:214) at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:88) at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:90) at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:61) at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java:28) at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:88) at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:315) at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:128) at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:94) at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:120) at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFinderInterceptor.java:93) at org.jboss.ejb.EntityContainer.internalInvokeHome(EntityContainer.java:478) at org.jboss.ejb.Container.invoke(Container.java:743) at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invokeHome(BaseLocalProxyFactory.java:294) at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java:110) at $Proxy193.create(Unknown Source)
I am using a third-party code generator that creates the deployment descriptors and all that stuff for me. I'm thinking that the problem lies somewhere there but I can't see what it is.
The DDL was created manually.
The symptom I am seeing is that the child elements are saved before the parent element. Since the constraints are defined on the database server (and I am not at liberty to remove them) it complains because the foreign key of the child points to a (as yet) non-existent parent. I don't understand what determines the storage order so I'm not sure what to change to make the parent be stored before the child(ren).
The database elements are created from a web page where all the data for the objects are collected and but in a Java object for storage.
My database server is SQL Server 2000 on Windows XP and I'm using JBoss 3.2.5.
Can anyone help?
Thanks,
L