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();
}}
***************************************************************************
<?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();
}}
解决方案 »
- java和c#通过webservice交互哪个做服务端哪个做客户端好
- 求解!
- ssh查询结果处理??
- eXtremeComponents 报表编译问题,我的安装没问题,有时候调用就出编译错误,有时候好用,大家帮忙,谢谢啊
- 关于json后台传值到前台页面的问题
- 看了几天的 struts 一般的简单代码能看明白了,但是还有个关键的问题没有搞清楚,谁来指点下我
- ■200分:Jbuilder9和Jboss4.0开发session bean(stateless),deploy成功,用testapplication调用出错?
- JUnit 的环境变量的问题,
- 感谢 zez 的讲解
- java matlab 报错
- 哪本书用JB9教struts?
- weblogic环境下支持EL语言吗?
<generator class="uuid.string"/>
</id>我用的是<id name="..." column="..." type="java.lang.string" >这样的没有问题
<generator class="uuid.string"/> 好象不是这样的,我也是刚刚用hibernate这个不是太清楚,你的程序报什么错啊
<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=哪个字段啊?
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
<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"/>
是我手工加进去的啊