How to model composite key in legacy database in grails
I have a legacy db with the three tables modeled by the Grails domain objects
class Foo {
static hasMany = [bars: Bar]
static mapping = {
version false
columns {
id column: "FooId"
fooProp column: "FooProp"
}
}
}
class Bar implements Serializable{
Baz baz
static hasMany = [foos: Foo]
static belongsTo = [Foo]
static mapping = {
version false
columns {
id composite: ["FooId", "BazId"]
baz column: "BazId"
barProp column: "BarProp"
}
}
}
class Baz {
static hasMany = [bars: Bar]
static mapping = {
version false
columns {
id column: "BazId"
bazProp column: "BazProp"
}
}
}
But when i try to deploy this I get the following exception
Caused by: 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.HibernateException: Missing column: id in app.Bar
I would rather not have the composite key but I have strict orders not to touch the DB so right now I'm doing my best to model it but composite keys has proven somewhat difficult...