Hi,
I am using hibernate 3.2 in combination with groovy and coldfusion.
In my application I created a customer-class and a permission-class represented by hibernate-entities.
Both are referenced in a bidirectional manyToMany relationship.
The code within the entities (I use the javax-lib for annotations):
customer:
Code:
...
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(name = "rel_customer_permission",
joinColumns = {
@JoinColumn( name = "fk_customerID", nullable = false )
},
inverseJoinColumns = {
@JoinColumn( name = "fk_permissionID", nullable = false )
}
)
List<Permission> permissions = new ArrayList<Permission>();
in permission-entity:
Code:
...
ManyToMany(mappedBy = "permissions", fetch = FetchType.LAZY)
List<Customer> customers = new ArrayList<Customer>();
At the first glance, this seems to work properly, because
hibernat represents this ralation in form of a regular n:m table - relationship (see following schema):
customer -> customerPermissions -> permission
---------- ---------------------- ----------
customerID customerID | permID permID
The problem is now:And if I want to store a bunch of permissions in a customer, it works perfectly well;
but when I try to add a single permission to a customer, it adds sometimes one permission (as it should do)
and sometimes it adds the permission-object two times. (the strange thing I can not comprehend, is why it works only ever and anon)
To make things even more obscure to me, trying to remove a single permission from the list of permissions that belong to a single customer,
causes consistently a server-time out, as if a dead-lock would block the whole server.
the code-fragments within the Data-Access-Object are:
... [for adding a permission]
Code:
customer.getPermissions().add( permission );
getPermissionDAO().saveOrUpdate( customer );
... [removing a permission-object]
Code:
customer.getPermissions().remove( permission );
getPermissionDAO().saveOrUpdate( customer );
I don't even know if that is a hibernate issue at all (?).
What are your suggestions about this phenomenon?
Thanx for helping in advance.