I keep getting this error when trying to delete a class from my system. Can anyone suggest how I might fix it.
Hibernate operation: Could not execute JDBC batch update; SQL [delete from intellectual_property where id=?]; Cannot delete or update a parent row: a foreign key constraint fails; nested exception is java.sql.BatchUpdateException: Cannot delete or update a parent row: a foreign key constraint fails
I have tried setting Set associated to NULL, saving the object then trying to delete it but end up in the same position.
************************** JAVA CLASS AND HIBERNATE SETTINGS *************************************
// Attributes =============================================================
private Long id;
private String title;
private String description;
private String acknowledgementNotes;
private String notes;
private String externalSystemID;
// Associations ===========================================================
public Set contentTypes = new HashSet(); // of type ContentType
public Long copyrightStatus;
public Set catalogs = new HashSet(); // of type Catalog
public Set storages = new HashSet(); // of type Storage
public Set contributors = new HashSet(); // of type Contributor
public Set licences = new HashSet(); // of type Licence
public Set usages = new HashSet(); // of type Use
public Set parents = new HashSet(); // of type IntellectualProperty parent element
public Set children = new HashSet(); // of type IntellectualProperty child elements
public Status status;
// Methods ================================================================
/**
* <p>
* Returns the unique identifier of the intellectual property. The
* identifier is unique only within the application instance.
* </p>
*
* @return Long
*
* @hibernate.id
* column="id"
* generator-class="native"
* unsaved-value="null"
*/
public Long getId() {
return id;
}
/**
* <p>
* Lists an id for the intellectual property. This method would not normally
* be called as the unique id would be set during creation of the record.
* </p>
*
* @param id The id to set.
*/
public void setId(Long id) {
this.id = id;
}
/**
* <p>
* Get the title
* </p>
*
* @return Returns the title.
*
* @hibernate.property
* column="title"
* type="text"
*/
public String getTitle() {
return title;
}
/**
* <p>
* Set the title
* </p>
* @spring.validator
* type="required"
* msgkey="intellectualProperty.title.required"
*
* @param title The title to set.
*/
public void setTitle(String title) {
this.title = title;
}
/**
* <p>
* Get the description
* </p>
*
* @return Returns the description.
*
* @hibernate.property
* column="description"
* type="text"
*/
public String getDescription() {
return description;
}
/**
* <p>
* Set the description
* </p>
*
* @param description The description to set.
*/
public void setDescription(String description) {
this.description = description;
}
/**
* @return Returns the acknowledgementNotes.
*
* @hibernate.property
* column="ack_notes"
* type="text"
*/
public String getAcknowledgementNotes() {
return acknowledgementNotes;
}
/**
* @param acknowledgementNotes The acknowledgementNotes to set.
*/
public void setAcknowledgementNotes(String acknowledgementNotes) {
this.acknowledgementNotes = acknowledgementNotes;
}
/**
* @return Returns the notes.
* @hibernate.property
* column="notes"
* type="text"
*/
public String getNotes() {
return notes;
}
/**
* @param notes The notes to set.
*/
public void setNotes(String notes) {
this.notes = notes;
}
/**
* @return Returns the contentType.
*
* @hibernate.set
* name="contentTypes"
* cascade="all"
* lazy="true"
*
* @hibernate.collection-key
* column="ip_content_type_id"
* @hibernate.collection-one-to-many
* class="au.edu.tlf.crisp2.model.ContentType"
*/
public Set getContentTypes() {
return contentTypes;
}
/**
* @param contentType The contentType to set.
*/
public void setContentTypes(Set contentTypes) {
this.contentTypes = contentTypes;
}
/**
* @return Returns the copyrightStatus.
*
* @hibernate.property
* column="copyright_status"
*/
public Long getCopyrightStatus() {
return copyrightStatus;
}
/**
* @spring.validator
* type="required"
* msgkey="intellectualProperty.copyrightStatus.required"
*
* @param copyrightStatus The copyrightStatus to set.
*/
public void setCopyrightStatus(Long copyrightStatus) {
this.copyrightStatus = copyrightStatus;
}
/**
* @return Returns the status.
* @hibernate.many-to-one
* column="fk_status_intellectual_property_id"
*/
public Status getStatus() {
return status;
}
/**
* @param status The status to set.
*/
public void setStatus(Status status) {
this.status = status;
}
/**
* <p>
* Returns a list of catalog numbers
* </p>
*
* @return Returns the catalogNumberList.
*
* @hibernate.set
* name="catalogs"
* cascade="all"
* lazy="true"
*
* @hibernate.collection-key
* column="ip_catalog_id"
*
* @hibernate.collection-one-to-many
* class="au.edu.tlf.crisp2.model.Catalog"
*/
public Set getCatalogs() {
return catalogs;
}
/**
* <p>
* Set the catalogue entries
* </p>
*
* @param catalogueNumberList The catalogueNumberList to set.
*/
public void setCatalogs(Set catalogNumbers) {
this.catalogs = catalogNumbers;
}
/**
* <p>
* Returns a list of catalog numbers
* </p>
*
* @return Returns the storages.
*
* @hibernate.set
* name="storages"
* cascade="all"
* lazy="true"
* @hibernate.collection-key
* column="ip_storage_id"
* @hibernate.collection-one-to-many
* class="au.edu.tlf.crisp2.model.Storage"
*/
public Set getStorages() {
return storages;
}
/**
* <p>
* Set the storage locations
* </p>
*
* @param storages The storages to set.
*/
public void setStorages(Set storages) {
this.storages = storages;
}
/**
* <p>
* Get the storage locations
* </p>
*
* @return Returns the contributors.
*
* @hibernate.set
* cascade="all"
* lazy="true"
* @hibernate.collection-key
* column="ip_contributor_id"
* @hibernate.collection-one-to-many
* class="au.edu.tlf.crisp2.model.Contributor"
*/
public Set getContributors() {
return contributors;
}
/**
* <p>
* Get the contributors
* </p>
*
* @param contributors The contributors to set.
*/
public void setContributors(Set contributors) {
this.contributors = contributors;
}
/**
* <p>
* Associate licences to intellectual property
* </p>
*
* @return Returns the licences.
*
* @hibernate.set
* table="table_ip_licence"
* lazy="true"
* cascade="save-update
* "
* @hibernate.collection-key
* column="fk_ip_id"
*
* @hibernate.collection-many-to-many
* class="au.edu.tlf.crisp2.model.Licence"
* column="fk_licence_id"
*/
public Set getLicences() {
return licences;
}
/**
* <p>
* Set the licences
* </p>
*
* @param licences The licences to set.
*/
public void setLicences(Set licences) {
this.licences = licences;
}
/**
* <p>
* Returns a list of catalog numbers
* </p>
*
* @return Returns the catalogNumberList.
*
* @hibernate.set
* name="usages"
* cascade="all"
* lazy="true"
*
* @hibernate.collection-key
* column="ip_usage_id"
*
* @hibernate.collection-one-to-many
* class="au.edu.tlf.crisp2.model.IntellectualPropertyUsage"
*/
public Set getUsages() {
return usages;
}
/**
* <p>
* Set to usage
* </p>
*
* @param usages The usages list to set.
*/
public void setUsages(Set usages) {
this.usages = usages;
}
/**
* @return Returns the parent intellectualProperties.
*
* @hibernate.set
* name="table_intellectual_property_composite"
* cascade="save-update"
* lazy="true"
*
* @hibernate.collection-key
* column="parent_id"
*
* @hibernate.collection-many-to-many
* class="au.edu.tlf.crisp2.model.IntellectualProperty"
* column="child_id"
*/
public Set getParents() {
return parents;
}
/**
* @param intellectualProperties The intellectualProperties to set.
*/
public void setParents(Set parents) {
this.parents = parents;
}
/**
* @return Returns the children.
*
* @hibernate.set
* table="table_intellectual_property_composite"
* cascade="save-update"
* lazy="true"
*
* @hibernate.collection-key
* column="child_id"
*
* @hibernate.collection-many-to-many
* class="au.edu.tlf.crisp2.model.IntellectualProperty"
* column="parent_id"
*/
public Set getChildren() {
return children;
}
/**
* @param children The children to set.
*/
public void setChildren(Set children) {
this.children = children;
}
/**
* @return Returns the externalSystemID.
* @hibernate.property
* column="external_system_id"
*/
public String getExternalSystemID() {
return externalSystemID;
}
/**
* @param externalSystemID The externalSystemID to set.
*/
public void setExternalSystemID(String externalSystemID) {
this.externalSystemID = externalSystemID;
}
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: