我使用JPA和休眠,并且具有@Entity
其包括@Embeddable
部件,其具有两个部件@Embeddable
本身,相同类型的,其具有与@OneToOne
关联的@ElementCollection
另一个@Entity
。JPA,休眠,嵌入式和OneToOne
基本上是:
@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;
// ...
}
(注意类的名称已被更改,以保护无辜的。)现在
,我遇到的问题是我得到想要的错误为AutoUpdate模式:
创建表company_employees(COMPANY_ID BIGINT NOT NULL,employees_collection & & element_residential_address_housing_info TINYBLOB,employees_collection & & element_postal_address_housing_info TINYBLOB)
的MySQL显然不喜欢&&
秒。我们使用的是org.hibernate.cfg.DefaultComponentSafeNamingStrategy
的子类,它不会在我能看到的任何地方插入&&
。
我试过@AssociationOverride
,但它似乎被忽略,无论我把它放在哪个级别。也就是说,我尝试覆盖Company
(List
等)上的Company
(@AssociationOverride(name = "residentialAddress.housingInfo', joinColumns = @JoinColumn(name = "residential_housing"))
等)中的属性,并在Employee
(@AssociationOverride(name = "housingInfo", joinColumns = @JoinColumn(name = "residential_housing"))
,residentialAddress
等等)中尝试了它,但是它们都没有做任何事情。