Here's the logging from when I execute the code described above "session.delete(lineItem.getProduct())":
Code:
10:30:31,588 DEBUG SessionImpl:413 - opened session
10:30:31,588 DEBUG JDBCTransaction:36 - begin
10:30:31,588 DEBUG SessionImpl:896 - deleting a transient instance
10:30:31,588 DEBUG SessionImpl:941 - deleting [common.structures.Product#2C90AA1E-00F7-00F7-0003-FFFFF7424A39]
10:30:31,588 DEBUG JDBCTransaction:54 - commit
10:30:31,604 DEBUG SessionImpl:2011 - flushing session
10:30:31,604 DEBUG SessionImpl:2113 - Flushing entities and processing referenced collections
10:30:31,604 DEBUG SessionImpl:2397 - Processing unreferenced collections
10:30:31,604 DEBUG SessionImpl:2408 - Scheduling collection removes/(re)creates/updates
10:30:31,604 DEBUG SessionImpl:2023 - Flushed: 0 insertions, 0 updates, 1 deletions to 1 objects
10:30:31,604 DEBUG SessionImpl:2028 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
10:30:31,604 DEBUG SessionImpl:2058 - executing flush
10:30:31,604 DEBUG EntityPersister:548 - Deleting entity: common.structures.Product#2C90AA1E-00F7-00F7-0003-FFFFF7424A39
10:30:31,604 DEBUG BatcherImpl:166 - about to open: 0 open PreparedStatements, 0 open ResultSets
10:30:31,604 DEBUG SessionFactoryImpl:526 - prepared statement get: delete from product where product_guid=?
Hibernate: delete from product where product_guid=?
10:30:31,604 DEBUG SessionFactoryImpl:536 - preparing statement
10:30:31,604 DEBUG StringType:44 - binding '2C90AA1E-00F7-00F7-0003-FFFFF7424A39' to parameter: 1
10:30:31,620 DEBUG JDBCExceptionReporter:36 - SQL Exception
com.jnetdirect.jsql.w: DELETE statement conflicted with COLUMN REFERENCE constraint 'FK_LINEITEM_PRODUCT'. The conflict occurred in database 'Test', table 'LINEITEM', column 'product_guid'.
at com.jnetdirect.jsql.av.a(Unknown Source)
at com.jnetdirect.jsql.ag.i(Unknown Source)
at com.jnetdirect.jsql.ag.new(Unknown Source)
at com.jnetdirect.jsql.ag.int(Unknown Source)
at com.jnetdirect.jsql.ap.executeUpdate(Unknown Source)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:207)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:207)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.persister.EntityPersister.delete(EntityPersister.java:575)
at net.sf.hibernate.impl.ScheduledDeletion.execute(ScheduledDeletion.java:22)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2100)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2066)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2005)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:57)
at integration.dao.ProductDataManagerImpl.delete(ProductDataManagerImpl.java:38)
at business.ProductController.delete(ProductController.java:15)
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 middle.CommandControllerImpl.doCommand(CommandControllerImpl.java:61)
at nico.presentation.PersistenceManager.deleteProduct(PersistenceManager.java:94)
at nico.presentation.HibernateClient.deleteMenu(HibernateClient.java:237)
at nico.presentation.HibernateClient.updateMenu(HibernateClient.java:163)
at nico.presentation.HibernateClient.start(HibernateClient.java:567)
at nico.presentation.HibernateClient.main(HibernateClient.java:594)
10:30:31,620 WARN JDBCExceptionReporter:38 - SQL Error: 547, SQLState: 23000
10:30:31,620 ERROR JDBCExceptionReporter:46 - DELETE statement conflicted with COLUMN REFERENCE constraint 'FK_LINEITEM_PRODUCT'. The conflict occurred in database 'Test', table 'PRODUCT', column 'product_guid'.
10:30:31,620 DEBUG BatcherImpl:173 - done closing: 0 open PreparedStatements, 0 open ResultSets
10:30:31,620 DEBUG SessionFactoryImpl:554 - closing statement
10:30:31,635 ERROR JDBCExceptionReporter:37 - Could not synchronize database state with session
com.jnetdirect.jsql.w: DELETE statement conflicted with COLUMN REFERENCE constraint 'FK_LINEITEM_PRODUCT'. The conflict occurred in database 'Test', table 'LINEITEM', column 'product_guid'.
at com.jnetdirect.jsql.av.a(Unknown Source)
at com.jnetdirect.jsql.ag.i(Unknown Source)
at com.jnetdirect.jsql.ag.new(Unknown Source)
at com.jnetdirect.jsql.ag.int(Unknown Source)
at com.jnetdirect.jsql.ap.executeUpdate(Unknown Source)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:207)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:207)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.persister.EntityPersister.delete(EntityPersister.java:575)
at net.sf.hibernate.impl.ScheduledDeletion.execute(ScheduledDeletion.java:22)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2100)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2066)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2005)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:57)
at integration.dao.ProductDataManagerImpl.delete(ProductDataManagerImpl.java:38)
at business.ProductController.delete(ProductController.java:15)
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 middle.CommandControllerImpl.doCommand(CommandControllerImpl.java:61)
at nico.presentation.PersistenceManager.deleteProduct(PersistenceManager.java:94)
at nico.presentation.HibernateClient.deleteMenu(HibernateClient.java:237)
at nico.presentation.HibernateClient.updateMenu(HibernateClient.java:163)
at nico.presentation.HibernateClient.start(HibernateClient.java:567)
at nico.presentation.HibernateClient.main(HibernateClient.java:594)
10:30:31,635 DEBUG SessionImpl:447 - transaction completion
Anf the SQL for creating the foreign key constraint:
Code:
ALTER TABLE [dbo].[LINEITEM] ADD
CONSTRAINT [FK_LINEITEM_ORDER] FOREIGN KEY
(
[order_guid]
) REFERENCES [dbo].[ORDER] (
[order_guid]
),
CONSTRAINT [FK_LINEITEM_PRODUCT] FOREIGN KEY
(
[product_guid]
) REFERENCES [dbo].[PRODUCT] (
[product_guid]
)
Have seen your latest posting while I was modifying the logging. Do you have any suggestions on what I should change?
* Remove the equals()/hashCode()?
* Change the equals()/hashCode() to include Product?
* What more properties need to be mapped?
What else?
Regards, Andreas