Quantcast
Channel: Spring Community Forums - Data
Viewing all articles
Browse latest Browse all 297

Many To Many insert is not Updating join table

$
0
0
I am having following Entity class:

@Entity
@Table(name = "USER")
public class User implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "USER_ID")
private Long id;

@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinTable(name="SUBSCRIBED_SUBJECTS",
joinColumns={@JoinColumn(name="USER_ID")},
inverseJoinColumns={@JoinColumn(name="SUBJECT_ID") })
private List<Subject> subjects;
// getters and setters
}


@Entity
@Table(name = "SUBJECT")
public class Subject implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "SUBJECT_ID")
private Long subjectID;

@ManyToMany(mappedBy = "subjects", fetch = FetchType.LAZY)
private List<User> users;

}

I am having set of values for Subjects and Users. But i couldnt able to update (insert) middle table. It is not updating/ saving.
I am using spring data JPA. Can anyone help me to solve this?

Viewing all articles
Browse latest Browse all 297

Trending Articles