0

次のドメイン クラスでは、起動時にこのマッピング例外が発生します。

「sessionFactory」という名前の Bean の作成中にエラーが発生しました: init メソッドの呼び出しに失敗しました。ネストされた 例外は org.hibernate.MappingException:Foreignkey (FKA9FB5C607D60EAE9:person_examschedule [testingcenter_examschedule_id dummy_table,testing_center_exam_schedule_testing_center_id,testing_center_exam_schedule_exam_schedule_id])) は、参照される主キー (testingcenter_examschedule [testingcenter_id,examschedule_id]) と同じ数の列を持つ必要があります

class TestingCenterExamSchedule implements Serializable{

Long testingCenterId
ExamSchedule examSchedule
TestingCenter testingCenter   
int bufferedSlots

static transients = ['testingCenter']

static constraints = {
    examSchedule nullable: false
    testingCenter nullable: false
    testingCenterId nullable: false
    bufferedSlots nullable:false
}

static mapping = {
    table 'testingcenter_examschedule'
    version false
    id composite: ['testingCenterId','examSchedule']
    testingCenterId column: 'testingcenter_id'
    examSchedule column: 'examschedule_id'
    bufferedSlots column: 'buffered_slots'

}

これは私の別のドメインクラスで、複合キーも持っています

class RegistrantTestingCenterExamSchedule implements Serializable {

Registrant registrant
TestingCenterExamSchedule testingCenterExamSchedule

static constraints = {
    registrant nullable: false
    testingCenterExamSchedule nullable: false
}

static mapping = {
    table 'person_examschedule'
    version: false
    id composite: ['registrant', 'testingCenterExamSchedule']
    columns {
        registrant column: 'person_id'
        testingCenterExamSchedule column: ['testingcenter_examschedule_id', 'dummy_table']
    }
}

この問題を解決するのに苦労しています。既存のスキーマのためにこれを機能させたいのですが、何が問題で、どのように修正するか教えてもらえますか?

知識を共有していただきありがとうございます。

4

2 に答える 2

0

TestingCenterExamSchedule では、testingCenter を一時的なプロパティとして宣言しましたが、GORM マッピングで問題が発生していないのでしょうか? いずれにせよ、列を不必要にマッピングしているように見えますが、既存/レガシーのテーブル スキーマにマッピングしている場合でも、定義した列の多くは自動的に作成されるはずです。

于 2012-04-25T15:00:26.887 に答える
0

これは私が直面している問題と同じだと思います。

ブラス タック: GORM-Hibernate のバグであることは間違いありません。ここにログを記録しました

回避策は、関連付けのマッピングを取り除き、関連付けを手動でロードするゲッターとセッターを作成することです。これは、すべてのユースケースで必ずしも十分ではありません。

¯\_(ツ)_/¯

于 2016-03-22T02:10:14.717 に答える