Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JPA ManytoMany Bidirectional relation throwing exception...  RSS feed

Muhammad Ahsan Jamshaid
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am facing difficulty in managing the many to many relation with JPA in my application. The sceen is like this.... Role & Dist_list have many to many relation among each other. beside the Role and Dist_List tables the relation is placed in another table role_dist_test table{role_id,dist_list_id}

IN relation is defined as

@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "role_dist_test", joinColumns = { @JoinColumn(name = "dist_id") },
inverseJoinColumns = { @JoinColumn(name = "role_id") })
private List<Role> roleList;

In the relation is defined as

@ManyToMany(cascade = CascadeType.ALL,mappedBy="roleList")
private List<DistributionList> distLists;

The scnerio is when i creat the new instances of each other it works fine. But i want to create a dist_list and associate it with an existing role. following is my code...

Role role = rmsService.findRoleById(1);
List<Role> rList = new ArrayList<Role>();

DistributionList dist = new DistributionList();
dist.setDescription("The temp");
dist.setName("Dist List 123");



it throws me ....Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: com.tabaq.rms.model.Role....... Can anyone help me what wrong with it...
--Ahsan Jamshaid...
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!