I'm using JPA and Hibernate, and have an @Entity
which includes an @ElementCollection
of an @Embeddable
component, which has two @Embeddable
components itself, of the same type, which have a @OneToOne
association with another @Entity
.
Basically:
@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;
// ...
}
(Note that the names of the classes have been changed to protect the innocent.)
Now, the problem I'm having is I'm getting an error trying to autoupdate the schema:
create table company_employees (company_id bigint not null, employees_collection&&element_residential_address_housing_info tinyblob, employees_collection&&element_postal_address_hou开发者_如何转开发sing_info tinyblob)
MySQL clearly doesn't like the &&
s. We're using a subclass of org.hibernate.cfg.DefaultComponentSafeNamingStrategy
, which doesn't insert &&
s anywhere that I can see.
I tried @AssociationOverride
, but it appeared to be ignored, regardless of which level I put it at. That is, I tried overriding the attributes in Company
(@AssociationOverride(name = "residentialAddress.housingInfo', joinColumns = @JoinColumn(name = "residential_housing"))
on the List
, etc.), and also tried it in Employee
(@AssociationOverride(name = "housingInfo", joinColumns = @JoinColumn(name = "residential_housing"))
on residentialAddress
, etc.), but neither seemed to do anything, at all.
Apparently @AttributeOverride
worked, even though, from the documentation, it seemed I was supposed to use @AssociationOverride
.
精彩评论