Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Spring 1.2.8
Mapping documents:
Copied below
Code between sessionFactory.openSession() and session.close():
Spring Hibernate 3 DAO
Full stack trace of any exception that occurs:
org.springframework.dao.DataIntegrityViolationException: Hibernate operation: Could not execute JDBC batch update; SQL [insert into CMS_ContentItem_Entity (id, elt) values (?, ?)]; Duplicate key or integrity constraint violation message from server: "Cannot add or update a child row: a foreign key constraint fails"; nested exception is java.sql.BatchUpdateException: Duplicate key or integrity constraint violation message from server: "Cannot add or update a child row: a foreign key constraint fails"
org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:92)
org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:258)
org.springframework.orm.hibernate3.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:424)
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:411)
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:371)
org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:690)
com.jafp.database.HibernateDao.saveOrUpdate(HibernateDao.java:26)
Name and version of the database you are using:
MySQL 4.1
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Please help I am getting this error:
org.springframework.dao.DataIntegrityViolationException: Hibernate operation: Could not execute JDBC batch update; SQL [insert into CMS_ContentItem_Entity (id, elt) values (?, ?)]; Duplicate key or integrity constraint violation message from server: "Cannot add or update a child row: a foreign key constraint fails"; nested exception is java.sql.BatchUpdateException: Duplicate key or integrity constraint violation message from server: "Cannot add or update a child row: a foreign key constraint fails"
My mappings are:
<class name="ContentItem" table="CMS_ContentItem">
<id name="id" column="id" type="integer" unsaved-value="0">
<generator class="native"/>
</id>
<property name="active"/>
<property name="status"/>
<property name="title"/>
<property name="description"/>
<!-- Complex types -->
<many-to-one name="itemType" class="Type"/>
<bag name="owners" table="CMS_ContentItem_Entity">
<key column="id"/>
<many-to-many class="Entity"/>
</bag>
<!-- Entity -->
<joined-subclass name="Entity" table="CMS_Entity">
<key column="id"/>
<property name="clubName"/>
<!-- Complex types -->
<set name="contact" table="CMS_Entity_Contact">
<key column="id"/>
<many-to-many class="com.jafp.objects.Contact" unique="true"/>
</set>
<set name="address" table="CMS_Entity_Address">
<key column="id"/>
<many-to-many class="com.jafp.objects.Address" unique="true"/>
</set>
</joined-subclass>
</class>
I have already set up a couple of entities in the database.
I am now trying to add a contentItem that is owned by an existing entity.
Is their an obvious reasons twhy this would break?
Thanks
Josh