Tôi đang cố sử dụng miền được nhúng với mối quan hệ nhiều người trong Grails 2.2.1. Đây là một phiên bản đơn giản của những gì tôi đang cố gắng làm.Thành phần GORM - miền được nhúng với mối quan hệ nhiều người-một-ném ném org.hibernate.MappingException
Tôi đang lập bản đồ các bảng db hiện:
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;
Domains rằng bản đồ để "sự cố" bảng:
class Incident {
Vehicle vehicle
static embedded = ['vehicle']
}
class Vehicle{
State state
static mapping = {
state column: 'state_id'
}
}
miền mà các bản đồ để "nhà nước" bảng:
class State {
String name
}
Khi tôi cố gắng chạy ứng dụng của mình, tôi nhận được lỗi sau:
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)]
Có thể có liên kết nhiều người trong miền được nhúng không?
- Cập nhật -
tôi đã kết thúc bằng một cách giải quyết để có được nhà nước.
class Vehicle{
static transients = [ "state" ]
Long stateId
static mapping = {
stateId column: 'state_id'
}
State getState(){
State.get(this.stateId)
}
}
tôi bắt đầu nghĩ rằng đây có thể là một lỗi grails ... Nghe có vẻ tương tự như http: //jira.grails.org/browse/GRAILS-9012 –