hbm.xml看起来像这样,我该如何实现等效的GORM类? “belongsTo”可以指定要映射的列吗?
我对hibernate了解不多,HBM中的声明是否是双向数据绑定?也就是说,如果我删除商品,评论是否会被删除?
<hibernate-mapping package="com.mictest.model">
<class name="CommentInfo" table="CommentInfo" dynamic-insert="true" dynamic-update="true">
<id name="commentId" column="CommentId" type="java.lang.Integer">
<generator class="identity"/>
</id>
<property
name="goodsId"
column="GoodsId"
update="true"
insert="true"
type="java.lang.Integer"
not-null="false"
unique="false"
length="10"/>
<many-to-one name="goods" class="com.mictest.Goods" fetch="select" insert="false" update="false">
<column name="goodsId" />
</many-to-one>
</hibernate-mapping>
答案 0 :(得分:0)
没有经过测试,但有些事情要开始。
package com.mictest.model
class CommentInfo {
static belongsTo = [goods: Goods]
static constraints = {
goods nullable:false
}
static mapping = {
id name:"commentId"
table "CommentInfo"
goods column: "goodsId", cascade:'save-update'
}
}
package com.mictest.Goods
class Goods{
// other goods properties here
static hasMany = [comments: CommentInfo]
}