Announcement Announcement Module
Collapse
No announcement yet.
Many To Many insert is not Updating join table Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Many To Many insert is not Updating join table

    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?

  • #2
    Problem solved. Problem is under Transaction attribute. I have mistakenly put it as @Transactional(readonly = true)

    Comment

    Working...
    X