Hi, thanks for your response, steve. Now, Hibernate try save data on the join table. But, the following error occur:
Code:
Hibernate: insert into JOIN_PURCHASE_GOODS (FK_PURCHASE_ID, FK_GOODS_ID, JOIN_PURCHASE_GOODS_QUANTITY) values (?, ?, ?)
04/08/2004 19:35:42 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 1048, SQLState: S1000
04/08/2004 19:35:42 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: General error, message from server: "Column 'FK_GOODS_ID' cannot be null"
04/08/2004 19:35:42 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 1048, SQLState: S1000
04/08/2004 19:35:42 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: General error, message from server: "Column 'FK_GOODS_ID' cannot be null"
04/08/2004 19:35:42 net.sf.hibernate.JDBCException <init>
SEVERE: Could not execute JDBC batch update
java.sql.BatchUpdateException: General error, message from server: "Column 'FK_GOODS_ID' cannot be null"
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1367)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeBatch(DelegatingPreparedStatement.java:231)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2417)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2371)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at org.springframework.orm.hibernate.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:386)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:316)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:211)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:138)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:148)
at $Proxy2.insert(Unknown Source)
at br.ufpe.scacin.manager.PurchaseManager.insert(PurchaseManager.java:95)
at br.ufpe.scacin.SCACInFacade.insert(SCACInFacade.java:314)
at br.ufpe.scacin.SCACInFacade.main(SCACInFacade.java:506)
04/08/2004 19:35:42 net.sf.hibernate.impl.SessionImpl execute
SEVERE: Could not synchronize database state with session
net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:129)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2417)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2371)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at org.springframework.orm.hibernate.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:386)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:316)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:211)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:138)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:148)
at $Proxy2.insert(Unknown Source)
at br.ufpe.scacin.manager.PurchaseManager.insert(PurchaseManager.java:95)
at br.ufpe.scacin.SCACInFacade.insert(SCACInFacade.java:314)
at br.ufpe.scacin.SCACInFacade.main(SCACInFacade.java:506)
Caused by: java.sql.BatchUpdateException: General error, message from server: "Column 'FK_GOODS_ID' cannot be null"
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1367)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeBatch(DelegatingPreparedStatement.java:231)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
... 13 more
04/08/2004 19:35:42 org.springframework.jdbc.support.SQLStateSQLExceptionTranslator translate
INFO: Translating SQLException with SQLState 'S1000' and errorCode '1048' and message [General error, message from server: "Column 'FK_GOODS_ID' cannot be null"]; SQL was [null] for task [HibernateTemplate]
org.springframework.jdbc.UncategorizedSQLException: (HibernateTemplate): encountered SQLException [General error, message from server: "Column 'FK_GOODS_ID' cannot be null"]; nested exception is java.sql.BatchUpdateException: General error, message from server: "Column 'FK_GOODS_ID' cannot be null"
java.sql.BatchUpdateException: General error, message from server: "Column 'FK_GOODS_ID' cannot be null"
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1367)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeBatch(DelegatingPreparedStatement.java:231)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2417)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2371)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at org.springframework.orm.hibernate.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:386)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:316)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:211)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:138)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:148)
at $Proxy2.insert(Unknown Source)
at br.ufpe.scacin.manager.PurchaseManager.insert(PurchaseManager.java:95)
at br.ufpe.scacin.SCACInFacade.insert(SCACInFacade.java:314)
at br.ufpe.scacin.SCACInFacade.main(SCACInFacade.java:506)
So, a try to set the cascade property to save-update on the relationship object like this:
Code:
/**
* Returns the value of {@link #goods} to this object.
*
* @hibernate.many-to-one cascade="save-update"
* class="br.ufpe.scacin.model.Goods"
* column = "FK_GOODS_ID"
* not-null="true"
*
* @return Returns the goods.
*/
public Goods getGoods() {
return this.goods;
}
I read the
faq but a can not see how to solve it.
valeuz...