I am working on a data model that basically consists of users and documents. Now everytime a new document is added, there should be a flag that identifies a document as "unseen" as long as the particular user did not had a look at it (e.g. clicked on it).
How would you model such a scenario ? Is there somehow a way to attach a boolean/flag to the relationship between users and documents ?
Here's my simplified model:
@Entity
@Table(name="User")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
@Column(length = 128)
private String name;
@ManyToMany(mappedBy = "users", fetch=FetchType.LAZY)
private List<Document> documents = new ArrayList<Document>();
// getters and setters ...
}
Here's the document class:
@Entity
@Table(name = "Document")
public class Document {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
@ManyToMany(fetch=FetchType.LAZY)
@JoinTable(name = "Inbox", joinColumns = @JoinColumn(name = "document_id"), inverseJoinColumns = @JoinColumn(name = "user_id"))
protected List<User> users = new ArrayList<User>();
// getters and setters ...
}
Many thanks for your help!