0

次のバージョンで Grails を使用します。

APPLICATION STATUS
App version: 0.1
Grails version: 2.3.5
Groovy version: 2.1.9
JVM version: 1.7.0_51
Reloading active: true
Controllers: 15
Domains: 18
Services: 2
Tag Libraries: 13

従おうとしているドメイン モデルがあります。プログラミングの前に、MySQL でテーブルを作成しました。
モデルには、多対多の関係で人 (Persons) にバインドされた Insertion_orders があります。この関係は Insertion_orders_persons によって定義され、person_id と location_id によって Insertion_orders_persons のエントリが定義されます。さらに、Trafficker、Advertiser、Agency、(または) Salesperson のいずれかが ENUM 化された type 値があります。常に 1 人 (または複数) のトラフィッカーが表示されますが、残りのトラフィッカーは、これらの関連付けの多くを持っている場合と、持っていない場合があります。タイプに応じて Insertion_orders モデルにバインドしようとしています。

package cms


class Insertion_orders {
    String insertion_order_name
    String po_number
    String notes
    String toString() {
        "${insertion_order_name} - ${id}"
    }

    static hasMany = [trafficker: Insertion_orders_traffickers, salesperson: Insertion_orders_salespersons]

    static constraints = {
        insertion_order_name(blank:false)
        po_number()
        notes(widget: 'textarea', nullable:true)
    }
    static mapping ={
        version false
        id column: 'insertion_order_id'
        notes sqlType: 'text'
    }
}

これを達成するために、継承と識別値を使用しようとしています。

package cms

class Insertion_orders_persons {
    Persons person
    Insertion_orders insertion_order
    Type type
    String toString() {
        "${person}: ${type}"
    }

    enum Type {
        Trafficker, Salesperson, Advertiser, Agency
    }

    static constraints = {
    }
    static mapping = {
        version false
        id column: 'insertion_order_person_id'
        discriminator column: "type"        
    }

}

class Insertion_orders_traffickers extends Insertion_orders_persons {
    static mapping ={
        discriminator value: "Traffickers"
    }
}

class Insertion_orders_salespersons extends Insertion_orders_persons {
    static mapping ={
        discriminator value: "Salesperson"
    }
}

問題は、拡張クラス (Insertion_orders クラスの hasMany など) に参加しようとすると、Grails が起動に失敗し、次のように生成されることです。

|Loading Grails 2.3.5
|Configuring classpath
.
|Environment set to development
.................................
|Packaging Grails application
..........................................
|Running Grails application
Error |
2014-04-16 11:33:58,693 [localhost-startStop-1] ERROR context.GrailsContextLoader  - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Association references unmapped class: cms.Insertion_orders_salespersons
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Association references unmapped class: cms.Insertion_orders_salespersons
    Line | Method
->>  262 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run       in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Association references unmapped class: cms.Insertion_orders_salespersons
->>  262 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run       in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Association references unmapped class: cms.Insertion_orders_salespersons
->>  262 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run       in java.lang.Thread
Caused by MappingException: Association references unmapped class: cms.Insertion_orders_salespersons
->>  262 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run       in java.lang.Thread
Error |
Forked Grails VM exited with error

追加情報として、サブクラスまたはサブクラスの構成にどのようにアクセスしようとしても、同じエラーが発生します。

これは非常に基本的な機能のようです。誰かが私が見逃していることや間違っていることを教えてもらえますか?

4

1 に答える 1

0

Discriminator column: “type” を Insertion_orders_persons から削除し、Insertion_orders_persons、Insertion_orders_traffickers、および Insertion_orders_salespersons をそれぞれ独自のソース ファイルで定義すると、コードが機能すると思います。

于 2014-04-16T17:08:37.410 に答える