-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Data Access Exception
PostPosted: Wed Jun 14, 2006 9:17 pm 
Beginner
Beginner

Joined: Thu Sep 23, 2004 6:03 am
Posts: 27
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:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 14, 2006 10:44 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Setting a collection property to null does nothing. Emptying the collection and saving (obj.get<set>().clear(); session.update(obj);) will do what you were thinking of... but it's not what you need to do to fix this.

You need to set the not-null="true" attribute of the <key> element inside each affected collection mapping. I have no idea how to do that using annotations, though.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 1:07 am 
Beginner
Beginner

Joined: Thu Sep 23, 2004 6:03 am
Posts: 27
I have updated to class to the following, adding your suggested not-null=true tags.

Code:
package au.edu.tlf.crisp2.model;

import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
* <p>
* Intellectual Property is an artifact or piece of knowledge that is to be used
* within a project. It will have a licence (and associated usage rights) associated with it.
* <p>
*
* </p>
*    This class is used to generate the Spring validation rules
*    as well as the Hibernate mapping file.
* </p>
*
* <p>
* <a href="IntellectualProperty.java.html"><i>View Source</i></a>
* </p>
*
* @author <a href="mailto:manpreet.minhas@thelearningfederation.edu.au">Manpreet Minhas</a>
*
* @hibernate.class
*      table="intellectual_property"
*/
public class IntellectualProperty extends BaseObject {

   // 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"
    *       not-null="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"
    *       not-null="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"
    *        not-null="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"
    *        not-null="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
    *        not-null="true"
    *
    * @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"
    *        not-null="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"
    *        not-null="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"
    *        not-null="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;
   }

   /**
    * @see java.lang.Object#equals(Object)
    */
   public boolean equals(Object object) {
      if (!(object instanceof IntellectualProperty)) {
         return false;
      }
      IntellectualProperty rhs = (IntellectualProperty) object;
      return new EqualsBuilder()
            .append(this.title,rhs.title)
            .append(this.notes, rhs.notes)
            .append(this.acknowledgementNotes, rhs.acknowledgementNotes)
            .append(this.description, rhs.description)
            .append(this.copyrightStatus,rhs.copyrightStatus)
            .append(this.status,rhs.status)
            .append(this.id,rhs.id)
            .isEquals();
   }

   /**
    * @see java.lang.Object#hashCode()
    */
   public int hashCode() {
      return new HashCodeBuilder(489588187, -1864837411)
            .append(this.title)
            .append(this.notes)
            .append(this.acknowledgementNotes)
            .append(this.description)
            .append(this.copyrightStatus)
            .append(this.status)
            .append(this.id)
            .toHashCode();
   }

   /**
    * @see java.lang.Object#toString()
    */
   public String toString() {
      return new ToStringBuilder(this)
            .append("id", this.id)
            .append("notes",this.notes)
            .append("copyrightStatus",this.copyrightStatus)
            .append("acknowledgementNotes",this.acknowledgementNotes)
            .append("description",this.description)
            .append("title", this.title)
            .append("status",this.status)
            .toString();
   }

}



The resulting hbm file is as follows, this what you were expecting to see as I still have the same result:

Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping

>

    <class
            name="au.edu.tlf.crisp2.model.IntellectualProperty"
            table="intellectual_property"
    >

    <id
        name="id"
            column="id"
            unsaved-value="null"
    >

    <!-- The generator-class attribute of @hibernate.id is deprecated, use the @hibernate.generator tag instead -->
    <generator class="native">

    </generator>

    </id>

        <property
            name="title"
                    type="text"
                    column="title"
        >

        </property>

        <property
            name="description"
                    type="text"
                    column="description"
        >

        </property>

        <property
            name="acknowledgementNotes"
                    type="text"
                    column="ack_notes"
        >

        </property>

        <property
            name="notes"
                    type="text"
                    column="notes"
        >

        </property>

        <set
            name="contentTypes"
            lazy="true"
            cascade="all"
        >

            <!-- @hibernate.collection-key tag is deprecated, use @hibernate.key instead -->
            <key
                column="ip_content_type_id"
            >

            </key>

            <!-- @hibernate.collection-one-to-many tag is deprecated, use @hibernate.one-to-many instead -->
            <one-to-many
                  class="au.edu.tlf.crisp2.model.ContentType"
            />

        </set>

        <property
            name="copyrightStatus"
                    column="copyright_status"
        >

        </property>

        <many-to-one
            name="status"
                    column="fk_status_intellectual_property_id"
        >

        </many-to-one>

        <set
            name="catalogs"
            lazy="true"
            cascade="all"
        >

            <!-- @hibernate.collection-key tag is deprecated, use @hibernate.key instead -->
            <key
                column="ip_catalog_id"
            >

            </key>

            <!-- @hibernate.collection-one-to-many tag is deprecated, use @hibernate.one-to-many instead -->
            <one-to-many
                  class="au.edu.tlf.crisp2.model.Catalog"
            />

        </set>

        <set
            name="storages"
            lazy="true"
            cascade="all"
        >

            <!-- @hibernate.collection-key tag is deprecated, use @hibernate.key instead -->
            <key
                column="ip_storage_id"
            >

            </key>

            <!-- @hibernate.collection-one-to-many tag is deprecated, use @hibernate.one-to-many instead -->
            <one-to-many
                  class="au.edu.tlf.crisp2.model.Storage"
            />

        </set>

        <set
            name="contributors"
            lazy="true"
            cascade="all"
        >

            <!-- @hibernate.collection-key tag is deprecated, use @hibernate.key instead -->
            <key
                column="ip_contributor_id"
            >

            </key>

            <!-- @hibernate.collection-one-to-many tag is deprecated, use @hibernate.one-to-many instead -->
            <one-to-many
                  class="au.edu.tlf.crisp2.model.Contributor"
            />

        </set>

        <set
            name="licences"
            table="table_ip_licence"
            lazy="true"
        >

            <!-- @hibernate.collection-key tag is deprecated, use @hibernate.key instead -->
            <key
                column="fk_ip_id"
            >

            </key>

            <!-- @hibernate.collection-many-to-many tag is deprecated, use @hibernate.many-to-many instead -->
            <many-to-many
                class="au.edu.tlf.crisp2.model.Licence"
                column="fk_licence_id"
                outer-join="auto"
             />

        </set>

        <set
            name="usages"
            lazy="true"
            cascade="all"
        >

            <!-- @hibernate.collection-key tag is deprecated, use @hibernate.key instead -->
            <key
                column="ip_usage_id"
            >

            </key>

            <!-- @hibernate.collection-one-to-many tag is deprecated, use @hibernate.one-to-many instead -->
            <one-to-many
                  class="au.edu.tlf.crisp2.model.IntellectualPropertyUsage"
            />

        </set>

        <set
            name="parents"
            lazy="true"
            cascade="save-update"
        >

            <!-- @hibernate.collection-key tag is deprecated, use @hibernate.key instead -->
            <key
                column="parent_id"
            >

            </key>

            <!-- @hibernate.collection-many-to-many tag is deprecated, use @hibernate.many-to-many instead -->
            <many-to-many
                class="au.edu.tlf.crisp2.model.IntellectualProperty"
                column="child_id"
                outer-join="auto"
             />

        </set>

        <set
            name="children"
            table="table_intellectual_property_composite"
            lazy="true"
            cascade="save-update"
        >

            <!-- @hibernate.collection-key tag is deprecated, use @hibernate.key instead -->
            <key
                column="child_id"
            >

            </key>

            <!-- @hibernate.collection-many-to-many tag is deprecated, use @hibernate.many-to-many instead -->
            <many-to-many
                class="au.edu.tlf.crisp2.model.IntellectualProperty"
                column="parent_id"
                outer-join="auto"
             />

        </set>

        <property
            name="externalSystemID"
                    column="external_system_id"
        >

        </property>

    </class>   

</hibernate-mapping>



Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 2:41 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
No, as you can see in the .hbm.xml file, there's no not-null="true" on the <key> elements. Looks like it belongs on the @hibernate.collection-key annotation, rather than the @hibernate.set.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 3:42 am 
Beginner
Beginner

Joined: Thu Sep 23, 2004 6:03 am
Posts: 27
Thank you for all your pointers but unfortunately I still have the same result. The problem I believe is with the getParents and getChild sets as they are a Set of intellectualProperty items too hence when an item of intellectaulproperty tries to delete and it does/ordoesn't have other intellectualproperty associated is seems to have a problem.

I added

[code]
/**
* @return Returns the children.
*
* @hibernate.set
* table="table_intellectual_property_composite"
* cascade="save-update"
* lazy="true"
*
* @hibernate.collection-key
* column="child_id"
* not-null="true"
*
* @hibernate.collection-many-to-many
* class="au.edu.tlf.crisp2.model.IntellectualProperty"
* column="parent_id"
*/
public Set getChildren() {
return children;
}
[code]

to all but again it doesn't even seem to enter it into the HBM file.

[code]<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping

>

<class
name="au.edu.tlf.crisp2.model.IntellectualProperty"
table="intellectual_property"
>

<id
name="id"
column="id"
unsaved-value="null"
>

<!-- The generator-class attribute of @hibernate.id is deprecated, use the @hibernate.generator tag instead -->
<generator class="native">

</generator>

</id>

<property
name="title"
type="text"
column="title"
>

</property>

<property
name="description"
type="text"
column="description"
>

</property>

<property
name="acknowledgementNotes"
type="text"
column="ack_notes"
>

</property>

<property
name="notes"
type="text"
column="notes"
>

</property>

<set
name="contentTypes"
lazy="true"
cascade="all"
>

<!-- @hibernate.collection-key tag is deprecated, use @hibernate.key instead -->
<key
column="ip_content_type_id"
>

</key>

<!-- @hibernate.collection-one-to-many tag is deprecated, use @hibernate.one-to-many instead -->
<one-to-many
class="au.edu.tlf.crisp2.model.ContentType"
/>

</set>

<property
name="copyrightStatus"
column="copyright_status"
>

</property>

<many-to-one
name="status"
column="fk_status_intellectual_property_id"
>

</many-to-one>

<set
name="catalogs"
lazy="true"
cascade="all"
>

<!-- @hibernate.collection-key tag is deprecated, use @hibernate.key instead -->
<key
column="ip_catalog_id"
>

</key>

<!-- @hibernate.collection-one-to-many tag is deprecated, use @hibernate.one-to-many instead -->
<one-to-many
class="au.edu.tlf.crisp2.model.Catalog"
/>

</set>

<set
name="storages"
lazy="true"
cascade="all"
>

<!-- @hibernate.collection-key tag is deprecated, use @hibernate.key instead -->
<key
column="ip_storage_id"
>

</key>

<!-- @hibernate.collection-one-to-many tag is deprecated, use @hibernate.one-to-many instead -->
<one-to-many
class="au.edu.tlf.crisp2.model.Storage"
/>

</set>

<set
name="contributors"
lazy="true"
cascade="all"
>

<!-- @hibernate.collection-key tag is deprecated, use @hibernate.key instead -->
<key
column="ip_contributor_id"
>

</key>

<!-- @hibernate.collection-one-to-many tag is deprecated, use @hibernate.one-to-many instead -->
<one-to-many
class="au.edu.tlf.crisp2.model.Contributor"
/>

</set>

<set
name="licences"
table="table_ip_licence"
lazy="true"
>

<!-- @hibernate.collection-key tag is deprecated, use @hibernate.key instead -->
<key
column="fk_ip_id"
>

</key>

<!-- @hibernate.collection-many-to-many tag is deprecated, use @hibernate.many-to-many instead -->
<many-to-many
class="au.edu.tlf.crisp2.model.Licence"
column="fk_licence_id"
outer-join="auto"
/>

</set>

<set
name="usages"
lazy="true"
cascade="all"
>

<!-- @hibernate.collection-key tag is deprecated, use @hibernate.key instead -->
<key
column="ip_usage_id"
>

</key>

<!-- @hibernate.collection-one-to-many tag is deprecated, use @hibernate.one-to-many instead -->
<one-to-many
class="au.edu.tlf.crisp2.model.IntellectualPropertyUsage"
/>

</set>

<set
name="parents"
lazy="true"
cascade="save-update"
>

<!-- @hibernate.collection-key tag is deprecated, use @hibernate.key instead -->
<key
column="parent_id"
>

</key>

<!-- @hibernate.collection-many-to-many tag is deprecated, use @hibernate.many-to-many instead -->
<many-to-many
class="au.edu.tlf.crisp2.model.IntellectualProperty"
column="child_id"
outer-join="auto"
/>

</set>

<set
name="children"
table="table_intellectual_property_composite"
lazy="true"
cascade="save-update"
>

<!-- @hibernate.collection-key tag is deprecated, use @hibernate.key instead -->
<key
column="child_id"
>

</key>

<!-- @hibernate.collection-many-to-many tag is deprecated, use @hibernate.many-to-many instead -->
<many-to-many
class="au.edu.tlf.crisp2.model.IntellectualProperty"
column="parent_id"
outer-join="auto"
/>

</set>

<property
name="externalSystemID"
column="external_system_id"
>

</property>

</class>

</hibernate-mapping>
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 4:55 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
As you can see in your produced .hbm.xml code, there's still no not-null="true" on the <key> element inside the <set> elements. I honestly don't know what you have to do in annotations to get that to appear, but that is your problem. You must find out what annoatation results in 'not-null="true"' appearing as an attribute on your <key> elements.
Code:
<!-- @hibernate.collection-key tag is deprecated, use @hibernate.key instead -->
<key
column="ip_content_type_id"
>

</key>
Also, there's a warning in your output: change your "hibernate.collection-key" annotations to "hibernate.key". Maybe it's as simple as that: perhaps collection-key doesn't support not-null but key does.

BTW, thanks for trying to use code tags. The next step to forum enlightenment is to use the preview button to check that you've got them right :)

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.