Guest User

Untitled

a guest
Apr 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. MappingException: Foreign key (FKk0e4770oa17lasc49nfp6mfxm:addresses [owner_object_type,owner_object_id])) must have same number of columns as the referenced primary key (contacts [id])
  2.  
  3. create table addresses(
  4. id bigint,
  5. owner_object_type varchar(40),
  6. owner_object_id bigint,
  7. address ...
  8. )
  9. create table companies(
  10. id bigint,
  11. legal_name varchar(80),
  12. name ...
  13. )
  14.  
  15. public interface AddressableDomainObject {
  16.  
  17. public String getObjectType();
  18. public long getId();
  19. }
  20.  
  21. @AnyMetaDef(
  22. name = "AddressableDomainObjectMetaDef",
  23. metaType = "string",
  24. idType = "long",
  25. metaValues = {
  26. @MetaValue(value = "CONTACT", targetEntity = Contact.class),
  27. @MetaValue(value = "COMPANY", targetEntity = Company.class)
  28. }
  29. )
  30.  
  31. @Entity
  32. @Table(name = "companies")
  33. @SequenceGenerator(name = "seq_companies", initialValue = 1)
  34. @DiscriminatorValue("COMPANY")
  35. public class Company implements AddressableDomainObject {
  36. @Id
  37. @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_companies")
  38. long id;
  39.  
  40. String name;
  41. String legalName;
  42. String companyType;
  43. Long parentCompanyId;
  44.  
  45.  
  46. @Override
  47. public final String getObjectType(){
  48. return "COMPANY";
  49. }
  50.  
  51. @OneToMany(
  52. mappedBy = "ownerObject",
  53. cascade = CascadeType.REMOVE)
  54. List<Address> addresses;
  55. }
  56.  
  57. @Entity
  58. @Table(name = "addresses")
  59. @SequenceGenerator(name = "seq_addresses", initialValue = 1)
  60. public class Address implements UsableDomainObject {
  61. @Id
  62. @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_addresses")
  63. private long id;
  64.  
  65. private String usage;
  66.  
  67. private String address;
  68. private String address2;
  69. private String city;
  70. private String state;
  71. private String postalCode;
  72. private String country;
  73. private String gpsCoordinates;
  74. private String notes;
  75.  
  76. @Any(
  77. metaDef = "AddressableDomainObjectMetaDef",
  78. metaColumn = @Column(name="owner_object_type")
  79. )
  80. @JoinColumn(name = "owner_object_id")
  81. private AddressableDomainObject ownerObject;
  82. }
Add Comment
Please, Sign In to add comment