2016-09-02 38 views
0

hbm.xml看起來像這樣,我如何實現等效的GORM類? 「belongsTo」可以指定映射哪個列嗎?如何實現像hibernate這樣的grails/gorm?

我對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> 
+2

你應該先閱讀一些信息,看看一些例子並試驗一下自己。這是學習的最佳方式。只需嘗試一些選項。 –

回答

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] 

} 
相關問題