2016-09-02 2 views
0

hbm.xmlは次のようになります。対応するGORMクラスを実装するにはどうすればよいですか? "belongsTo"はマップする列を指定できますか?この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] 

} 
関連する問題