我尝试在两个表之间创建链接:User
和 Notifications
Notifications
表应包含:
- ID(整数)
- User_Id(整数)
- 列出<用户>
我需要明确我的目标。在我的应用程序中,用户使用通知表向其他几个人询问一些问题。这样,我们就可以知道:
- 提出问题的用户是谁 (User_Id)
- 向哪些用户提出问题(列表<用户>)
用户
@Entity
public class User extends Model{
@ManyToOne
@JoinColumn(name="notification_fk")
public Notifications notification;
}
通知
@Entity
public class Notifications extends Model{
@Id
@GeneratedValue
public int id;
public User user;
@OneToMany(cascade=CascadeType.ALL, mappedBy="notifications")
public List<User> asked_users = new ArrayList<User>();
}
但我收到以下错误:
javax.persistence.PersistenceException: Error on models.Notifications.asked_users Can not find mappedBy property [user] in [models.User]
我做错了什么?
最佳答案
在mappedBy
中,您需要使用现有相反字段的名称,它是notification
您的案例 - 末尾没有's'。
关于mysql - 映射通过 Ebean/Play 框架的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29340233/