The hbm.xml looks like this, How can I implement the equivalent GORM class? Does "belongsTo" can specify which column to map?
I don't know much about hibernate, is the declaration in HBM a bidirectional data binding or not? That is, if I delete the goods, will the comment be deleted?
<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>
not tested but something to start with.
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]
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.