[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - ManyToMany problem: removing referenced records

nico.ben do-not-reply at jboss.com
Wed Mar 14 10:12:22 EDT 2007


Hi,
I am working with ManyToMany annotation and I cannot obtain the behaviour I'd like to. I need for this forum's help.
 
I have these tables:

SkillTypes:  
id_skill_type
...


Operations:
id_operation
...


R_operations_skills:
id_r_operation_skill    PK
id_operation   FK
id_skill_type    FK


In my 2 entity beans (I don't have a EJB for the relation table R_operations_skills) I used these annotations:

Operation.java

@ManyToMany(cascade={CascadeType.REFRESH, CascadeType.PERSIST}, fetch=FetchType.LAZY)
  |     @JoinTable(name="r_operations_skills",
  |                joinColumns=@JoinColumn(name="id_operation"),
  |                inverseJoinColumns=@JoinColumn(name="id_skill_type"))
  |     @OrderBy("description")
  | 	public List<SkillType> getSkillTypes() {
  | 		return skillTypes;
  | 	}
  | 



SkillType.java

@ManyToMany(cascade={CascadeType.REFRESH, CascadeType.PERSIST}, fetch=FetchType.LAZY)
  |     @JoinTable(name="r_operations_skills",
  |                joinColumns=@JoinColumn(name="id_skill_type"),
  |                inverseJoinColumns=@JoinColumn(name="id_operation"))
  |     @OrderBy("description")
  | 	public List<Operation> getOperations() {
  |     	if(operations == null) {
  |     		operations = new ArrayList<Operation>();
  |     	}
  | 		return this.operations;
  | 	}


My problem is that deleting a skill which has relations with operations, the skill is removed from SkillTypes and also records in the relation table are deleted.
I exptected that I cannot delete a skillType used in the relation.
Could you please suggest me how to solve my problem?

Thank u
Nico

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4027931#4027931

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4027931



More information about the jboss-user mailing list