我有一个包含更多字段的可选子实体的实体。子实体再次具有元素集合。
这对Hibernate来说通常是不可能的,还是我错过了什么?
@Entity @Table(name="my_entity")
public class MyEntity {
@Id
private Long id;
@Embedded
@JoinTable(name="..." joinColumns=@JoinColumn(name="myEntityId"))
private OptionalFields optionalFields;
}
@Embeddable
public class OptionalFields {
@ElementCollection
@CollectionTable(name="...", joinColumns=@JoinColumn(name="myEntityId"))
private List<OpeningHoursItem> openingHours;
}
@Embeddable
public class OpeningHoursItem {
}
错误信息是:
Could not determine type for: java.util.List, at table: my_entity, for columns: [org.hibernate.mapping.Column(opening_hours)]
答案 0 :(得分:0)
这可能听起来很奇怪,但确实有效:
将所有注释从字段移到getter,然后错误消失。