JPA,Hibernate,Embedded和OneToOne

时间:2011-03-08 14:30:01

标签: hibernate jpa

我正在使用JPA和Hibernate,并且@Entity包含@ElementCollection@Embeddable组件,该组件本身有两个@Embeddable组件类型,与另一个@OneToOne具有@Entity关联。

基本上:

@Entity
public class Company {
    // ...
    @ElementCollection
    private List<Employee> employees;
    // ...
}

@Embeddable
public class Employee {
    // ...
    @Embedded
    private Address residentialAddress;
    @Embedded
    private Address postalAddress;
    // ...
}

@Embeddable
public class Address {
    // ...
    @OneToOne
    private HousingInfo housingInfo;
    // ...
}

(请注意,已更改类的名称以保护无辜者。)

现在,我遇到的问题是我在尝试自动更新架构时遇到错误:

  

create table company_employees(company_id bigint not null,employees_collection&amp;&amp; element_residential_address_housing_info tinyblob,employees_collection&amp;&amp; element_postal_address_housing_info tinyblob)

MySQL显然不喜欢&&。我们正在使用org.hibernate.cfg.DefaultComponentSafeNamingStrategy的子类,它不会在我能看到的任何地方插入&&

我尝试了@AssociationOverride,但无论我把它放在哪个级别,它似乎都被忽略了。也就是说,我尝试覆盖Company@AssociationOverride(name = "residentialAddress.housingInfo', joinColumns = @JoinColumn(name = "residential_housing"))上的List等)中的属性,并在Employee@AssociationOverride(name = "housingInfo", joinColumns = @JoinColumn(name = "residential_housing"))residentialAddress进行了尝试{1}}等等,但似乎都没有做任何事情。

1 个答案:

答案 0 :(得分:0)

显然@AttributeOverride工作,即使从文档中看起来我应该使用@AssociationOverride