It looks like it is working now.
Here are the data related to the two classes:
Parent:
........................
<set name="RuleContextKws" inverse="true" cascade="all-delete-orphan" lazy="false">
<key column="rule_id"/>
<one-to-many class="RuleContextKw" />
</set>
.........................
Child: (the child has a composite key but this should not be relevant)
....................................
<composite-id name="Id" class="RuleContextKWPK">
<key-many-to-one
name="RuleId"
column="rule_id"
class="Rule"
/>
<key-property
name="Keyword"
column="keyword"
type="string"
length="50"
/>
</composite-id>
......................................
The code just creates a session when loading the parent object from the DB and then it closes it. By having now the reference of the whole object the client just plays around with the Set of children adding and/or removing entries in the collection.
Eventually a new session is open along with a new transaction and the update (or save) parent method is invoked.
Code:
Transaction tx = null;
Session session = null;
Integer id = null;
try {
RuleInfoDAO rules = RuleInfoDAO.getInstance();
session = rules.createNewSession();
tx = rules.beginTransaction(session);
//..........there is some code which detects if we need to save or update
if(.....)
id = rules.save(rule, session);//in case of new parent object
else
rules.update(rule, session);//in case of an existing parent object
rules.commitTransaction(tx);
rules.closeSession(session);
About the database I don't know if it is related but verything started to work when I added the cascade constraint on the foreign key to the parent table.
I hope this can help even the others who are struggling with this kind of issues.