Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MappingException: Foreign key (FKk0e4770oa17lasc49nfp6mfxm:addresses [owner_object_type,owner_object_id])) must have same number of columns as the referenced primary key (contacts [id])
- create table addresses(
- id bigint,
- owner_object_type varchar(40),
- owner_object_id bigint,
- address ...
- )
- create table companies(
- id bigint,
- legal_name varchar(80),
- name ...
- )
- public interface AddressableDomainObject {
- public String getObjectType();
- public long getId();
- }
- @AnyMetaDef(
- name = "AddressableDomainObjectMetaDef",
- metaType = "string",
- idType = "long",
- metaValues = {
- @MetaValue(value = "CONTACT", targetEntity = Contact.class),
- @MetaValue(value = "COMPANY", targetEntity = Company.class)
- }
- )
- @Entity
- @Table(name = "companies")
- @SequenceGenerator(name = "seq_companies", initialValue = 1)
- @DiscriminatorValue("COMPANY")
- public class Company implements AddressableDomainObject {
- @Id
- @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_companies")
- long id;
- String name;
- String legalName;
- String companyType;
- Long parentCompanyId;
- @Override
- public final String getObjectType(){
- return "COMPANY";
- }
- @OneToMany(
- mappedBy = "ownerObject",
- cascade = CascadeType.REMOVE)
- List<Address> addresses;
- }
- @Entity
- @Table(name = "addresses")
- @SequenceGenerator(name = "seq_addresses", initialValue = 1)
- public class Address implements UsableDomainObject {
- @Id
- @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_addresses")
- private long id;
- private String usage;
- private String address;
- private String address2;
- private String city;
- private String state;
- private String postalCode;
- private String country;
- private String gpsCoordinates;
- private String notes;
- @Any(
- metaDef = "AddressableDomainObjectMetaDef",
- metaColumn = @Column(name="owner_object_type")
- )
- @JoinColumn(name = "owner_object_id")
- private AddressableDomainObject ownerObject;
- }
Add Comment
Please, Sign In to add comment