Details
Description
I found this problem in mapping a composite id as foreign key in a one-to-many association:
here is my class with composite id:
class IntCau implements Serializable { static mapping = { table 'int_cau' version false id composite: ['c1', 'c2', 'c3'], generator: "assigned" } int c1 char c2 int c3 static HasMany = [attScheds: AttSched, attProgrs: AttProgr] static mappedBy = [attScheds: 'causale', attProgrs: 'causale'] }
this is in relation one-to-many with two other classes (which have pretty much the same code):
class AttProgr {
static mapping = {
table 'att_sched'
version false
columns {
causale column: ['c1_int_cau', 'c2_int_cau', 'c3_int_cau']
}
IntCau causale
}
i get this error:
Invocation of init method failed; nested exception is org.codehaus.groovy.grails.exceptions.InvalidPropertyException: No property found for name [attProgrs] for class [class IntCau]
so i insert the following declaration in the IntCau class:
List<AttSched> attScheds List<AttProgr> attProgrs
and now the error became:
Invocation of init method failed; nested exception is org.hibernate.MappingException: Foreign key (FKE0C5693A41F5AA0A:att_progr [c1_int_cau, c2_int_cau, c3_int_cau,int_cau_c1,int_cau_c2,int_cau_c3])) must have same number of columns as the referenced primary key (int_cau [c1,c2,c3])
What's wrong? If i do the same on a class with simple foreign key all works! It's a bug?
I found a similar issue marked as resolved but my my problem still remain in new release 1.1
(http://jira.codehaus.org/browse/GRAILS-3506)
I also try to define the class in this way:
class AttProgr {
static mapping = {
table 'att_sched'
version false
columns {
causale column: ['c1_int_cau', 'c2_int_cau', 'c3_int_cau']
int_cau_c1 column: 'c1_int_cau'
int_cau_c2 column: 'c2_int_cau'
int_cau_c3 column: 'c3_int_cau'
}
IntCau causale
int int_cau_c1
char int_cau_c2
int int_cau_c3
}
compiling is ok, but in the browser i found the same exception.
and now the problem is in columns mapping:
Invocation of init method failed; nested exception is org.codehaus.groovy.grails.exceptions.GrailsDomainException: Error evaluating ORM mappings block for domain [AttProgr]: No such property: causale for class: GroovyObjectSupport_groovyProxy
Sorry the last row:
{ causale column: ['c1_int_cau', 'c2_int_cau', 'c3_int_cau'] int_cau_c1 column: 'c1_int_cau' int_cau_c2 column: 'c2_int_cau' int_cau_c3 column: 'c3_int_cau' }columns
is:
columns
{ causale column: ['c1_int_cau', 'c2_int_cau', 'c3_int_cau'] int_cau_c1 column: 'c1_int_cau' int_cau_c2 column: 'c2_int_cau' int_cau_c3 column: 'c3_int_cau' }