4

このクラスの列名をマップしようとしています:

class Amount{

    String total //Total amount of something
    String type  //Type of amount, Dollars, %, Times something
    Bonification bonificationRate  //the amount can be "x times another bonification"

    static belongsTo = [parentBonification: Bonification]

    static mapping = {
       table "AMOUNTS"
       total column: "AMOU_TTOTAL"
       type column: "AMOU_TTYPE"
       parentBonification column: "BONI_CID"
       bonificationRate column: "BONI_TRATE_CID"
    }

}


class Bonification {  
    //among other things:  
    Amount amount
}

問題は、クラスのフィールドがBonificationDBに作成されておらず、私が付けた名前でも、デフォルトで想定されている名前でもないということです。

コメント編集:

  1. どちらもドメインクラスです。
  2. データソースはオンですdbCreate = "update"
  3. テーブルをOracleにドロップし、Grailsに再度作成させました。まだBonification列はありません。
  4. dbCreate = "create-drop"今のところ削除できないデータがあるのでできません。
  5. を使用して新しいローカルDerbyデータベースをマウントしましたdbCreate = create-drop。まだ運がない。

(PD:他のすべてのフィールドは永続化され、正しい列名でマップされます。これら2つのBonificationフィールドのみが問題になります)
これを行う別の方法はありますか?

Grails:1.3.9
BD:Oracle 9

要求されたDataSource.groovyの編集 (Config.groovyからアクセスされる外部ファイル grails.config.locations = [ "file:${extConfig}/${appName}Config.groovy"]

package xx.xxx.xxxx.xxxXxxx

dataSource 
{
    pooled = true
    dialect = "org.hibernate.dialect.Oracle10gDialect"
    driverClassName = "oracle.jdbc.OracleDriver"    
    username = "XXX"
    password = "XXX" 
    properties {
                maxActive = 100
                maxIdle = 25
                minIdle = 5
                initialSize = 5
                minEvictableIdleTimeMillis = 60000
                timeBetweenEvictionRunsMillis = 60000
                maxWait = 10000
                validationQuery = "select 1 from dual"
                }

}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = true
    cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
}

// environment specific settings
environments {
    development {
println "Including external DataSource"
        dataSource {            
            dbCreate = "update"
            url = "jdbc:oracle:thin:@xxx.xxx.xx:xxxx:XXXX"
        }
    }
}
4

1 に答える 1

4

わかりました、ついに私はそれを手に入れました。

「mappedBy」プロパティを使用しました。

http://grails.org/doc/2.1.0/ref/Domain%20Classes/mappedBy.html

ドキュメント ( 6.2.1.2 One-to-many ) は、「hasMany」側で使用するためのものであると述べています。hasMany ではなく、同じタイプの 2 つのフィールドが にあったため、混乱しましたClass Amount。そして、私が本当にしなければならなかったのは、Amount クラスではなく、への参照が 1 つしかない Bonification クラスで、mappedBy プロパティを使用することでしたAmount

そして、私はAmount Class、Bonification に、「彼」が混乱しないように後方参照を行う必要があることを伝えます。bonificationRateまた、フィールドを参照としてではなく、フィールドとして使用する必要があります。

class Amount{

    String total //Total amount of something
    String type  //Type of amount, Dollars, %, Times something
    Bonification bonificationRate  //the amount can be "x times another bonification"

    static belongsTo = [parentBonification: Bonification]

    static mapping = {
       table "AMOUNTS"
       total column: "AMOU_TTOTAL"
       type column: "AMOU_TTYPE"
       parentBonification column: "BONI_CID"
       bonificationRate column: "BONI_TRATE_CID"
    }

}


class Bonification {  
    //among other things:  
    Amount amount

    static mappedBy = [amount: "parentBonification"]
}

それは作成しませんでしたが、必要なものをparentBonification "BONI_CID" column作成しましたbonificationRate "BONI_TRATE_CID"

雑すぎてすみません。とにかく助けてくれてありがとう。

于 2013-01-04T20:35:01.573 に答える