我想有相同的领域类的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