I'm having problems with a many-to-one relationship. I have an organization object that is associated with many resources. The association is bidirectional. Here is the mapping:
Organization:
Code:
/**
* @hibernate.set lazy="false"
* cascade="none"
* table="resource"
* inverse="true"
*
* @hibernate.collection-key column="organization_key"
*
* @hibernate.collection-one-to-many class="xxxx.domain.Resource"
*/
public Set getResources() {
Resource:
Code:
/**
* @hibernate.many-to-one column="organization_key" not-null="false"
* access="field"
*/
public Organization getOrganization() {
Save/update seems to work correctly. The resource table's organization_key column is populated correctly. However, I am encountering a problem when I try to delete the resource. My delete code is as follows:
Code:
public void delete(Resource resource) {
getHibernateTemplate().delete(resource);
getHibernateTemplate().flush();
}
This yields the following error when executing the flush():
Code:
2006-11-07 15:24:10,750 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 01004
2006-11-07 15:24:10,750 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Data truncation: Column set to default value; NULL supplied to NOT NULL column 'organization_key' at row 1
2006-11-07 15:24:10,750 [main] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:181)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:138)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:815)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
at org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:813)
at com.silversky.scheduler.dao.organization.AbstractOrganizationDaoImpl.flush(AbstractOrganizationDaoImpl.java:87)
at com.silversky.scheduler.dao.organization.AbstractOrganizationDaoImpl.delete(AbstractOrganizationDaoImpl.java:82)
Any ideas on the cause of this error?