Mornor
Mornor

Reputation: 3793

mappedBy issue with Ebean/Play framework

I try to create a link between two tables : User and Notifications
The Notifications tables should have:

  1. Id (int)
  2. User_Id (int)
  3. List < User >

I need to clarify my goal. In my app, a user ask something to several others, using notifications tables. So that, we can know:

  1. Who is the user who asks the question (User_Id)
  2. To whow users the question is aked (List< User >)

User

@Entity
public class User extends Model{
    @ManyToOne
    @JoinColumn(name="notification_fk")
    public Notifications notification; 
}

Notifications

@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>();
}

But I get the following error:

javax.persistence.PersistenceException: Error on models.Notifications.asked_users Can not find mappedBy property [user] in [models.User]

What did I do wrong?

Upvotes: 0

Views: 1056

Answers (1)

biesior
biesior

Reputation: 55798

In the mappedBy you need to use the name of the existing oposite field, and it's notification in your case - without 's' at the end.

Upvotes: 1

Related Questions