I have an object ObjectA which has a property Set, having collection of objects ObjectB,
i.e in ObjectA class, i have
private Set objectB = new HashSet();
I want to delete one of the collection objects, "ObjectB", associated with ObjectA
(i.e one of the objects in Set objectB as mentioned above)
--- the mapping from ObjectB to ObjectA is MANY-TO-ONE
--- the associating COLUMN in ObjectB is ObjectAId, as below
--- this is the code of ObjectB Class
/**
* @return com.abc.xyz.ObjectA
*
* @hibernate.many-to-one
* column="ObjectAId"
* not-null="true"
* lazy="false"
* @hibernate.cache usage="read-write"
*/
public ObjectA getObjectA() {
return objectA;
}
Please note that the mapping column attribute,
not-null="true"
what i do is ::
for ( Iterator itr = ObjectA.getObjectB().iterator(); i.hasNext();) {
ObjectBClass objB = (ObjectBClass) itr.next;
if (objB.getName().equals("ABC")) {
itr.remove();
}
}
When i save ObjectA... the following is the error ::
ERROR:
java.sql.SQLException: Cannot insert the value NULL into column 'ObjectAId', table 'Table-OBJECTB'; column does not allow nulls. UPDATE fails.
I understand that when i make the not-null attribute to "false"
it works, i.e. if i do :: not-null="false" it deletes the row in the table.
BUT is there any other way I can delete, without changing the Mapping attribute ??
When I change the not-null="false"
-- it sets the column value of the ObjectB table, to NULL
Please let me know if I can delete, without changing the mapping.
Thanks,
anand
|