Hibernate中的一个<many-to-one>问题?望高手指点啊
<hibernate-mapping>
<class name="com.jpcf.db.model.Cltype" table="CLTYPE">
<id name="id" type="int" unsaved-value="21">
<column name="id" sql-type="int" not-null="true"/>
<generator class="identity"/>
</id>
<property name="name"/>
<property name="type"/>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="com.jpcf.db.model.VehicleProperty" table="VEHICLEPROPERTY">
<id name="id" type="int" unsaved-value="null">
<column name="id" sql-type="int" not-null="true"/>
<generator class="identity"/>
</id>
<property name="licese"/>
<property name="unit"/>
<property name="shelf"/>
<property name="engine"/>
<property name="color"/>
<property name="certifyDate"/>
<many-to-one name="cltype_id" class="com.jpcf.db.model.Cltype" insert="false" update="false" column="id" outer-join="true"/>
</class>
</hibernate-mapping>
对于Cltype中的值,在VehicleProperty中我并不想修改它
我在VehicleProperty类中
对<many-to-one>定义的cltype_id该定义
Cltype 的getter,setter
还是cltype_id 的getter,setter?
或者是两个都要定义啊?
帮忙啊,我已经调了两天了,都没搞定啊,高手帮忙啊!
问题点数:20、回复次数:5Top
1 楼Chendreamer(君默)回复于 2004-12-01 18:58:35 得分 0
1.
allVehicle = session.find("from VehicleProperty vp");
在VehicleProperty查询时报错:
now row with the given identifier exists:1,of class:com.jpcf.db.model.Cltype
2.
Session session = HibernateUtil.currentSession();
tx = session.beginTransaction();
Cltype ct=(Cltype)session.load(Cltype.class,new Integer(vpform.getClType_id()));
vp.setCltype(ct);
session.save(vp);
tx.commit();
新增数据时报错:
net.sf.hibernate.MappingException:No persister for:java.lang.Integer
怎么解决啊?
Top
2 楼Chendreamer(君默)回复于 2004-12-01 21:00:08 得分 0
hibernate中对每一个<many-to-one>是不是都要有一个<one-to-many>对应啊?Top
3 楼yxhzj(余华[学习J2EE中])回复于 2004-12-01 21:10:44 得分 20
呵呵,不会吧,具体的我也没看,你去它的中文网站看看相关资料吧Top
4 楼Chendreamer(君默)回复于 2004-12-01 21:34:15 得分 0
就是搞不定啊
有没有人知道啊?Top
5 楼jollyznlznl()回复于 2004-12-03 19:18:37 得分 0
你好!!
我想你还是看一看基础的hibernate设置把Top




