I have a pool which contains poolclients. I want to do the same thing as in the hibernate manual 22.3 (last case).
I use this code to delete a poolclient:
Code:
pool.removePoolClient(pc);
session.flush();
I always get a constraint error for the poolclient however (which should be deleted)
org.hibernate.PropertyValueException: not-null property references a null or transient value: epaper.server.model.PoolClient.pool
These are my settings:
pool.hbmCode:
<set name="poolClients" inverse="true" cascade="all-delete-orphan">
<key column="POOL_ID_REF"/>
<one-to-many class="PoolClient"/>
</set>
poolclient.hbmCode:
<many-to-one name="pool" column="POOL_ID_REF" not-null="true"/>
Pool.javaCode:
public void removePoolClient(PoolClient pc) {
getPoolClients().remove(pc);
pc.setPool(null);
}
I suspect that getPoolClients().remove(pc) doesn't work. If I put getPoolClients.contains(pc) in the removePoolClient method, it always answers false, even if the pool contains a poolclient with the same id...
Here is my equals method in PoolClient:
Code:
public boolean equals(Object obj) {
if (null == obj)
return false;
if (!(obj instanceof epaper.server.model.PoolClient))
return false;
else {
epaper.server.model.PoolClient client = (epaper.server.model.PoolClient) obj;
if (null == this.getId() || null == client.getId())
return false;
else
return (this.getId().equals(client.getId()));
}
}
Can someone help me cause I'm really stuck here...