Sto tentando di utilizzare un dominio incorporato con una relazione molti-a-uno in Grails 2.2.1. Ecco una versione semplificata di ciò che sto cercando di fare.Composizione GORM - dominio incorporato con relazione molti-a-uno getta org.hibernate.MappingException
sto mappatura di tabelle db esistenti:
create table incident (id bigint generated by default as identity, state_id bigint not null, primary key (id));
create table state (id bigint generated by default as identity, name varchar(255) not null, primary key (id));
alter table incident add constraint FK52F44D27499E79E foreign key (state_id) references state;
Domini che mappano a "incidente" tavolo:
class Incident {
Vehicle vehicle
static embedded = ['vehicle']
}
class Vehicle{
State state
static mapping = {
state column: 'state_id'
}
}
dominio che mappa "stato" tavolo:
class State {
String name
}
Quando provo a eseguire la mia applicazione, ottengo il seguente errore:
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: Could not determine type for: test.State, at table: incident, for columns: [org.hibernate.mapping.Column(vehicle_state)]
È possibile avere un'associazione many-to-one all'interno di un dominio incorporato?
- Aggiornamento -
ho finito per usare una soluzione per ottenere lo stato.
class Vehicle{
static transients = [ "state" ]
Long stateId
static mapping = {
stateId column: 'state_id'
}
State getState(){
State.get(this.stateId)
}
}
sto iniziando a pensare che questo potrebbe essere un bug graal ... suoni simili a http: //jira.grails.org/browse/GRAILS-9012 –