I created objects User and Message, and now I want, that message's id will be associated with the user id. How can I do it with annotations or with something else? Table User Table Messge
Message class
@Entity
public class Message {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String text;
private String tag;
}
User class
@Entity
@Table(name = "usr")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String username;
private String password;
private boolean active;
@ElementCollection(targetClass = Role.class , fetch = FetchType.LAZY)
@CollectionTable(name = "user_role" , joinColumns = @JoinColumn(name = "user_id"))
@Enumerated(EnumType.STRING)
private Set<Role> roles;
}