Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Eclipselink merge does not insert a new row in many-to-many relationship(eclipselink merge, many-to-many)
Eclipselink merge does not insert a new row in many-to-many relationship [message #1464346] Fri, 07 November 2014 12:54 Go to next message
Sina Alizadeh is currently offline Sina AlizadehFriend
Messages: 1
Registered: November 2014
Junior Member
I have a many-to-many relationship between user and role entities. when I try to merge a new role by adding new user objects to that, after merging i expect a new row in the joined table (in sql server database) to be inserted but nothing happens and I really don't know what the problem could be. Would you please check this out. Thanks in advance. Smile

@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinTable(
            name = "SEC_USER_ROLE",
            joinColumns = {
                @JoinColumn(name = "SEC_USER_ID", referencedColumnName = "SEC_USERS")},
            inverseJoinColumns = {
                @JoinColumn(name = "SEC_ROLE_ID", referencedColumnName = "SEC_ROLES")})
    private List<Role> roles;  


@ManyToMany(mappedBy = "roles", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<User> users;


@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public T merge(T o) {

    o = em.merge(o);
    em.flush();
    return o;
}
Re: Eclipselink merge does not insert a new row in many-to-many relationship [message #1469951 is a reply to message #1464346] Wed, 12 November 2014 01:49 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
If you are only modifying one side of the relationship and calling merge, that is the source of your problem. You have a bidirectional relationship and since the user->Role side is set to own the relationship in the database, that side needs to be set for the changes to be synchronized into the database. JPA mandates though that you modify both sides of your bidirectional relationship to ensure they remain in synch with the database - it will not modify your pojo's for you.

Best Regards,
Chris
Previous Topic:EclipseLink ddlgen doesn't work in eclipse
Next Topic:convert mapping source to mapping XML
Goto Forum:
  


Current Time: Sat Mar 02 10:26:51 GMT 2024

Powered by FUDForum. Page generated in 0.01813 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top