Product.hbm.xml
***************************************************************************
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.redstoneinfo.auwebsite4customer.hibernate.Product" table="product">
<id name="id" column="id" type="string">
<generator class="uuid.hex"/>
</id>
<property name="productid" column="productId" type="string" length="100" not-null="true"/>
<property name="name" column="name" type="string" length="100"/>
<property name="imagepath" column="imagePath" type="string" length="200"/>
<property name="listprice" column="listprice" type="string" length="100"/>
<property name="cost" column="cost" type="string" length="100"/>
<property name="unitcost" column="unitcost" type="string" length="100"/>
<property name="inventoryid" column="inventoryId" type="string" length="100"/>
<property name="grossweight" column="grossweight" type="string" length="100"/>
<property name="suttle" column="suttle" type="string" length="100"/>
<property name="manufacturename" column="manufactureName" type="string" length="100"/>
<property name="manufacturepartno" column="manufacturePartNo" type="string" length="100"/>
<property name="description" column="description" type="string" length="65535"/>
<property name="shortdescription" column="shortdescription" type="string" length="65535"/>
<many-to-one name="category" class="com.redstoneinfo.auwebsite4customer.hibernate.CategoryDetails" outer-join="auto" update="true" insert="true" column="categoryid"/>
</class>
</hibernate-mapping>*********************************************************************
Product .java
**********************************************************************
package com.redstoneinfo.auwebsite4customer.hibernate;import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;/** @author Hibernate CodeGenerator */
public class Product implements Serializable {    /** identifier field */
    private String id;    /** persistent field */
    private String productid;    /** nullable persistent field */
    private CategoryDetails categoryDetails;    /** nullable persistent field */
    private String name;    /** nullable persistent field */
    private String imagepath;    /** nullable persistent field */
    private String listprice;    /** nullable persistent field */
    private String cost;    /** nullable persistent field */
    private String unitcost;    /** nullable persistent field */
    private String inventoryid;    /** nullable persistent field */
    private String grossweight;    /** nullable persistent field */
    private String suttle;    /** nullable persistent field */
    private String manufacturename;    /** nullable persistent field */
    private String manufacturepartno;    /** nullable persistent field */
    private String description;    /** nullable persistent field */
    private String shortdescription;    /** full constructor */
    public Product(String productid, String name, String imagepath, String listprice, String cost, String unitcost, String inventoryid, String grossweight, String suttle, String manufacturename, String manufacturepartno, String description, String shortdescription, CategoryDetails categoryDetails) {
        this.productid = productid;
        this.categoryDetails = categoryDetails;
        this.name = name;
        this.imagepath = imagepath;
        this.listprice = listprice;
        this.cost = cost;
        this.unitcost = unitcost;
        this.inventoryid = inventoryid;
        this.grossweight = grossweight;
        this.suttle = suttle;
        this.manufacturename = manufacturename ;
        this.manufacturepartno = manufacturepartno;
        this.description = description;
        this.shortdescription = shortdescription;
    }    /** default constructor */
    public Product() {
    }    /** minimal constructor */
    public Product(String productid) {
        this.productid = productid;
    }    public String getId() {
        return this.id;
    }    public void setId(String id) {
        this.id = id;
    }    public String getProductid() {
        return this.productid;
    }    public void setProductid(String productid) {
        this.productid = productid;
    }    public CategoryDetails getCategory() {
        return this.categoryDetails;
    }    public void setCategory(CategoryDetails categoryDetails) {
        this.categoryDetails = categoryDetails;
    }    public String getName() {
        return this.name;
    }    public void setName(String name) {
        this.name = name;
    }    public String getImagepath() {
        return this.imagepath;
    }    public void setImagepath(String imagepath) {
        this.imagepath = imagepath;
    }    public String getListprice() {
        return this.listprice;
    }    public void setListprice(String listprice) {
        this.listprice = listprice;
    }    public String getCost() {
        return this.cost;
    }    public void setCost(String cost) {
        this.cost = cost;
    }    public String getUnitcost() {
        return this.unitcost;
    }    public void setUnitcost(String unitcost) {
        this.unitcost = unitcost;
    }    public String getInventoryid() {
        return this.inventoryid;
    }    public void setInventoryid(String inventoryid) {
        this.inventoryid = inventoryid;
    }    public String getGrossweight() {
        return this.grossweight;
    }    public void setGrossweight(String grossweight) {
        this.grossweight = grossweight;
    }    public String getSuttle() {
        return this.suttle;
    }    public void setSuttle(String suttle) {
        this.suttle = suttle;
    }    public String getManufacturename() {
        return this.manufacturename;
    }    public void setManufacturename(String manufacturename) {
        this.manufacturename = manufacturename;
    }    public String getManufacturepartno() {
        return this.manufacturepartno;
    }    public void setManufacturepartno(String manufacturepartno) {
        this.manufacturepartno = manufacturepartno;
    }    public String getDescription() {
        return this.description;
    }    public void setDescription(String description) {
        this.description = description;
    }    public String getShortdescription() {
        return this.shortdescription;
    }    public void setShortdescription(String shortdescription) {
        this.shortdescription = shortdescription;
    }    public String toString() {
        return new ToStringBuilder(this)
            .append("id", getId())
            .toString();
    }    public boolean equals(Object other) {
        if ( !(other instanceof Product) ) return false;
        Product castOther = (Product) other;
        return new EqualsBuilder()
            .append(this.getId(), castOther.getId())
            .isEquals();
    }    public int hashCode() {
        return new HashCodeBuilder()
            .append(getId())
            .toHashCode();
    }}

解决方案 »

  1.   

    <id name="catid" column="catid" type="string" length="50">
    <generator class="uuid.string"/>
    </id>我用的是<id name="..." column="..." type="java.lang.string" >这样的没有问题
    <generator class="uuid.string"/> 好象不是这样的,我也是刚刚用hibernate这个不是太清楚,你的程序报什么错啊
      

  2.   

    请问
    <set name="products" table="product" lazy="false" inverse="false" cascade="all" sort="unsorted">
    <key column="category_detailsid"/>
    <one-to-many class="com.redstoneinfo.auwebsite4customer.hibernate.Product"/>
    </set>
    中,key column=哪个字段啊?
      

  3.   


    Hibernate: select product0_.id as id, product0_.productId as productId, product0_.name as name, product0_.imagePath as imagePath, product0_.listprice as listprice, product0_.cost as cost, product0_.unitcost as unitcost, product0_.inventoryId as inventor8_, product0_.grossweight as grosswei9_, product0_.suttle as suttle, product0_.manufactureName as manufac11_, product0_.manufacturePartNo as manufac12_, product0_.description as descrip13_, product0_.shortdescription as shortde14_, product0_.categoryid as categoryid from product product0_ where (product0_.imagePath like '%1%' ) order by  product0_.id
    Hibernate: select category0_.catid as catid, category0_.name as name, category0_.superiorid as superiorid, category0_.level as level from category_details category0_ where category0_.catid=?
    2004-08-10 19:30:18 [com.redstoneinfo.auwebsite4customer.business.Pagination@b7f2d0]-[ERROR]:142 - net.sf.hibernate.ObjectNotFoundException: No row with the given identifier exists: , of class: com.redstoneinfo.auwebsite4customer.hibernate.CategoryDetails
      

  4.   

    主键?我建了主键啊,而且其他都是用工具生成的,就只是
    <set name="products" table="product" lazy="false" inverse="false" cascade="all" sort="unsorted">
    <key column="category_detailsid"/>
    <one-to-many class="com.redstoneinfo.auwebsite4customer.hibernate.Product"/>
    </set>

    <many-to-one name="category" class="com.redstoneinfo.auwebsite4customer.hibernate.CategoryDetails" outer-join="auto" update="true" insert="true" column="categoryid"/>
    是我手工加进去的啊
      

  5.   

    那你<key column="category_detailsid"/>是什么意思啊
      

  6.   

    我就是不知道key column应该等于哪个字段
      

  7.   

    哪个表的主键啊?你能不能把你写的贴出来给小弟看看啊?我们可以MSN联系啊,你小弟的MSN是[email protected]
      

  8.   

    不好意思,多打了个“你”字,小弟的MSN是[email protected]
      

  9.   

    你可以去hibernate的坛论去问问
      

  10.   

    这个问题应该不难啊,用过hibernate的应该都知道啊
      

  11.   

    小弟真的喊不动啦,用过Hibernate的好心人救救小弟吧!
      

  12.   

    看了你的CategoryDetails.java 文件,发现只有superiorid这个字段,而没有category_detailsid这个字段,你是写错了吧。