[Beginner's Corner] - Re: ManyToMany problem
by swenu
Hi again :D
i found a solution - at least i'm close to a solution.
I added this function to the Role.
| @OneToMany(mappedBy="role")
| private List<RoleFunction> listRoleFunctions;
| ...
| public List<Function> getFunctions(){
| List<Function> functions = new ArrayList<Function>();
| if(this.listRoleFunctions != null){
| for(RoleFunction rf:this.listRoleFunctions){
| Function f = new Function();
| f = rf.getFunction();
| functions.add(f);
| }
| }
| return functions;
| }
|
| public void setFunctions(List<Function> functions){
| if(functions.size() > this.listRoleFunctions.size()){
| //New function to add
| for(Function f:functions){
| boolean add = true;
| for(RoleFunction roleFunction:this.listRoleFunctions){
| if(roleFunction.getId().equals(f.getId())){
| add = false;
| break;
| }
|
| }
| if(add){
| RoleFunction rf = new RoleFunction();
| rf.setFunction(f);
| rf.setRole(this);
| System.out.println("Adding (rf from lRF)"+rf.getRole().getName() +"."+rf.getFunction().getName());
| this.listRoleFunctions.add(rf);
| }
| }
| }else{
| //Function to remove
| System.out.println("remove function");
| for(RoleFunction roleFunction:this.listRoleFunctions){
| boolean remove = true;
| for(Function f:functions){
| if(roleFunction.getId().equals(f.getId())){
| remove = false;
| break;
| }
| }
| if(remove){
| this.listRoleFunctions.remove(roleFunction);
| }
| }
| }
| }
|
The only thing which doesn't work is if a user deselect a already saved function assignment.
I always get this error:
10:49:58,960 INFO [STDOUT] remove function
| 10:49:58,960 SEVERE [component] /roleList.xhtml @72,106 value="#{roleHome.instance.functions}": Error writing 'functions' on type ch.emtm.entity.Role
| java.util.ConcurrentModificationException
| at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
| at java.util.AbstractList$Itr.next(AbstractList.java:343)
| at org.hibernate.collection.AbstractPersistentCollection$IteratorProxy.next(AbstractPersistentCollection.java:577)
| ...
Hope someone got input to solve this issue!
Thanks in advance for any hint
Greets
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4263631#4263631
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4263631
15 years