Hibernate父子关系类父类列出子集时出错,帮忙看下!

freeman102414 2007-07-05 11:11:40
---- ProductInfo类----
public class ProductInfo implements java.io.Serializable {


// Fields

private Integer piid;
private ProductTypeInfo productTypeInfo;
private byte[] piphoto;


// Constructors

/** default constructor */
public ProductInfo() {
}


/** full constructor */
public ProductInfo(ProductTypeInfo productTypeInfo, byte[] piphoto) {
this.productTypeInfo = productTypeInfo;
this.piphoto = piphoto;
}


// Property accessors

public Integer getPiid() {
return this.piid;
}

public void setPiid(Integer piid) {
this.piid = piid;
}

public ProductTypeInfo getProductTypeInfo() {
return this.productTypeInfo;
}

public void setProductTypeInfo(ProductTypeInfo productTypeInfo) {
this.productTypeInfo = productTypeInfo;
}

public byte[] getPiphoto() {
return this.piphoto;
}

public void setPiphoto(byte[] piphoto) {
this.piphoto = piphoto;
}

}


---- ProductInfo.hbm.xml---

<?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">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="org.bean.ProductInfo" table="productInfo" schema="dbo" catalog="ShengDian">
<id name="piid" type="integer">
<column name="PIid" />
<generator class="increment" />
</id>
<many-to-one name="productTypeInfo" class="org.bean.ProductTypeInfo" fetch="select">
<column name="PTid" not-null="true" />
</many-to-one>
<property name="piphoto" type="binary">
<column name="PIphoto" not-null="true" />
</property>
</class>
</hibernate-mapping>


------ProductTypeInfo 类----

public class ProductTypeInfo implements java.io.Serializable {


// Fields

private Integer ptid;
private String ptname;
private byte[] ptpartphoto;
private byte[] ptplanephoto;
private Integer ptgermproof;
private Integer ptheating;
private Set productRecommends = new HashSet(0);
private Set productInfos = new HashSet(0);


// Constructors

/** default constructor */
public ProductTypeInfo() {
}

/** minimal constructor */
public ProductTypeInfo(String ptname, byte[] ptpartphoto, byte[] ptplanephoto, Integer ptgermproof, Integer ptheating) {
this.ptname = ptname;
this.ptpartphoto = ptpartphoto;
this.ptplanephoto = ptplanephoto;
this.ptgermproof = ptgermproof;
this.ptheating = ptheating;
}

/** full constructor */
public ProductTypeInfo(String ptname, byte[] ptpartphoto, byte[] ptplanephoto, Integer ptgermproof, Integer ptheating, Set productRecommends, Set productInfos) {
this.ptname = ptname;
this.ptpartphoto = ptpartphoto;
this.ptplanephoto = ptplanephoto;
this.ptgermproof = ptgermproof;
this.ptheating = ptheating;
this.productRecommends = productRecommends;
this.productInfos = productInfos;
}


// Property accessors

public Integer getPtid() {
return this.ptid;
}

public void setPtid(Integer ptid) {
this.ptid = ptid;
}

public String getPtname() {
return this.ptname;
}

public void setPtname(String ptname) {
this.ptname = ptname;
}

public byte[] getPtpartphoto() {
return this.ptpartphoto;
}

public void setPtpartphoto(byte[] ptpartphoto) {
this.ptpartphoto = ptpartphoto;
}

public byte[] getPtplanephoto() {
return this.ptplanephoto;
}

public void setPtplanephoto(byte[] ptplanephoto) {
this.ptplanephoto = ptplanephoto;
}

public Integer getPtgermproof() {
return this.ptgermproof;
}

public void setPtgermproof(Integer ptgermproof) {
this.ptgermproof = ptgermproof;
}

public Integer getPtheating() {
return this.ptheating;
}

public void setPtheating(Integer ptheating) {
this.ptheating = ptheating;
}

public Set getProductRecommends() {
return this.productRecommends;
}

public void setProductRecommends(Set productRecommends) {
this.productRecommends = productRecommends;
}

public Set getProductInfos() {
return this.productInfos;
}

public void setProductInfos(Set productInfos) {
this.productInfos = productInfos;
}

}

------ProductTypeInfo.hbm.xml---------

<?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">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="org.bean.ProductTypeInfo" table="productTypeInfo"
schema="dbo">
<id name="ptid" type="integer">
<column name="PTid" />
<generator class="increment" />
</id>
<property name="ptname" type="string">
<column name="PTname" length="50" not-null="true" />
</property>
<property name="ptpartphoto" type="binary">
<column name="PTpartphoto" not-null="true" />
</property>
<property name="ptplanephoto" type="binary">
<column name="PTplanephoto" not-null="true" />
</property>
<property name="ptgermproof" type="integer">
<column name="PTgermproof" not-null="true" />
</property>
<property name="ptheating" type="integer">
<column name="PTheating" not-null="true" />
</property>
<set name="productInfos" inverse="true" ">
<key>
<column name="PTid" not-null="true" />
</key>
<one-to-many class="org.bean.ProductInfo" />
</set>
</class>
</hibernate-mapping>


---------出错位置----------

ProductTypeInfo pti = (ProductTypeInfo) session.load(ProductTypeInfo.class,new Integer(1));

Set set = pti.getProductInfos();//这个位置总是出错



麻烦知道的帮忙指点一下!谢谢!
...全文
237 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuanjun1107 2007-07-06
  • 打赏
  • 举报
回复
<many-to-one name="productTypeInfo" class="org.bean.ProductTypeInfo" fetch="select">
<column name="PTid" not-null="true" 这里加 lazy="false"/>
</many-to-one>
yuanjun1107 2007-07-06
  • 打赏
  • 举报
回复
要设一下,加载属性,设置 lazy="false;"
freeman102414 2007-07-05
  • 打赏
  • 举报
回复
补充一下异常:
org.hibernate.exception.GenericJDBCException: could not initialize a collection: [org.bean.ProductTypeInfo.productInfos#1]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1441)
at org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:111)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1430)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:176)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
at org.hibernate.collection.PersistentSet.size(PersistentSet.java:110)
at org.test.Test.findbyPTI_PTid(Test.java:155)
at org.test.Test.cs(Test.java:199)
at org.test.Test.main(Test.java:205)
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]ResultSet can not re-read row data for column 1.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.validateColumnIndex(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.getInt(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.getInt(Unknown Source)
at org.hibernate.type.IntegerType.get(IntegerType.java:26)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
at org.hibernate.persister.collection.AbstractCollectionPersister.readKey(AbstractCollectionPersister.java:633)
at org.hibernate.loader.Loader.readCollectionElement(Loader.java:648)
at org.hibernate.loader.Loader.readCollectionElements(Loader.java:370)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:314)
at org.hibernate.loader.Loader.doQuery(Loader.java:412)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1434)

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧