问题描述:

The following Domain class gives this Mapping Exception on startup:

Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is

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]))

must have same number of columns as the referenced primary key

(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'

}

and this is my another domain class which is also has a composite key

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']

}

}

I'm having a hard time to solve this problem, and I want to make this work because of my existing schema, can anyone tell me what's the problem and how to fix it?

Thanks for sharing your knowledge.

网友答案:

In TestingCenterExamSchedule you've declared testingCenter as a transient property, I wonder if that's not causing issues with the GORM mapping? At any rate you seem to be unnecessarily mapping columns, many of those you've defined should get created automatically, even if you're mapping to an existing/legacy table schema.

网友答案:

I believe this is the same issue I'm facing.

Brass tacks: pretty sure it's a bug with GORM-Hibernate, which I've logged here.

Workaround would be to strip off the association mappings and create getters and setters which manually load your associations for you. This wouldn't necessarily be sufficient for all use cases.

\_()_/

相关阅读:
Top