gpt4 book ai didi

hibernate - 如何像 hibernate 一样实现这个grails/gorm?

转载 作者:行者123 更新时间:2023-12-02 15:51:12 25 4
gpt4 key购买 nike

hbm.xml 看起来像这样,如何实现等效的 GORM 类? “belongsTo”是否可以指定要映射的列?

我对hibernate不太了解,HBM中的声明是双向数据绑定(bind)吗?也就是我删除商品,评论会被删除吗?

<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>

最佳答案

未经测试,但可以开始。

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]

}

关于hibernate - 如何像 hibernate 一样实现这个grails/gorm?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39285243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com