我想有相同的領域類的2場在我的實體,我得到這個錯誤:JPA實體與同類型的兩個字段
org.hibernate.MappingException: Could not determine type for: com.packt.webapp.domain.User, at table: opinions, for columns: [org.hibernate.mapping.Column(author)]
我的實體:
@Entity
@Table(name="opinions")
public class Opinion {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@NotNull
private String text;
@NotNull
private String date;
@ManyToOne
@JoinColumn(name="commented_user")
private User writtenTo;
private User author;
@Entity
@Table(name="user")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String username;
private String password;
@OneToMany(mappedBy="writtenTo")
private List<Opinion> opinions;
我只是想將意見映射到評論用戶和評論的存儲作者author
字段中。當我刪除author
字段時,一切正常。這個例子有什麼不對?
爲什麼不從'User'中刪除'List views'並用JPQL查詢? –
michaeak
您是否試圖爲Written和作者使用ManyToOne批註? – jmw5598
@michaeak你的意思是有2個簡單的字段,如:'commentedUser'和'author'?這是個好主意:)但我只是想知道爲什麼我的代碼不工作。 – crooked