###前提・実現したいこと
下記のようなjoinをjpaで実現したいです。
sql
1select p.parent_name, c.* from Parent p inner join Child c on p.parent_id= c.parent_id;
###entity情報
一部実際の実装に近い形に修正しました 12/22 09:37
java
1@Table(name = "parent_table") 2@Entity 3public class Parent implements Serializable { 4 private static final long serialVersionUID = 8058371942878604902L; 5 @EmbeddedId 6 private ParentKey parentKey = new parentKey(); 7 @Column(name = "parent_name") 8 private String parentName; 9 @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) 10 @JoinColumn(name = "parent_id", referencedColumnName = "parent_id") 11 @NotFound(action=NotFoundAction.IGNORE) 12 private List<Child> childList; 13 14 /** getter,setter省略 **/ 15 16 public static class ParentKey implements Serializable { 17 private static final long serialVersionUID = -795173904285910114L; 18 @Column(name = "hoge_id") 19 String hogeId; 20 @Column(name = "parent_id") 21 String parentId; 22 } 23 24 /** equals,hashCode省略 **/ 25} 26 27@Table(name = "child_table") 28@Entity 29public class Child implements Serializable { 30 private static final long serialVersionUID = 1718966005562173513L; 31 @EmbeddedId 32 private ChildKey childKey = new childKey(); 33 @Column(name = "child_name") 34 private String childName; 35 @ManyToOne 36 @JoinColumn(name = "parent_id", referencedColumnName = "parent_id") 37 private Parent parent; 38 39 /** getter,setter省略 **/ 40 41 public static class ChildKey implements Serializable { 42 private static final long serialVersionUID = -3848325403357861609L; 43 @Column(name = "child_id") 44 String childId; 45 @Column(name = "parent_id") 46 String parentId; 47 } 48 49 /** equals,hashCode省略 **/ 50}
###発生している問題・エラーメッセージ
上記の状態で、起動すると下記のエラーが出ます。
Caused by: org.hibernate.AnnotationException: referencedColumnNames(parent_id) of xx.xx.xxx.Child.parent referencing xx.xx.xxx.Parent not mapped to a single property
もう二日くらい悩んでおります・・・
やっぱJPAやめようかな
###補足情報(言語/FW/ツール等のバージョンなど)
必要そうなものだけ
java8
spring boot 1.3.0.RELEASE
spring-data-jpa-1.9.1.RELEASE
hibernate-jpa-2.1-api-1.0.0.Final
回答2件
あなたの回答
tips
プレビュー