I am using hibernate 3.05 and postgresql 8.0
I have users table and a userdetails table. the relation users.hbm.xml is
[code] <set name="userdetailses" lazy="false" inverse="true" cascade="all">
<key>
<column name="userid" length="50" not-null="true" />
</key>
<one-to-many class="com.arete.temsa.hibernate.Userdetails" />
</set>[/code]
I use versioning. I create a version field in all my tables. and I define it like that
[code]<version name="version" column="version" type="long"></version>[/code]
Now to my question. I get a List of Users object with Hibernate and send them jsp. In my jsp I choose to delete one of the users. I send the whole Users information to my Servlet ( actually I use spring, hibernatedaosupport ) I regenarate the Users object and try to delete but I got an constraintviolationexception due to foreign key from users to userdetails.
If I load the Users object with load( String key ), and then try to delete, it is succesful, however this time I cannot make version control.
I first load the users Object with
[code]Users obj = usersDao.get( usersArray[i].getUsername() );[/code]
then try to set the verison with
[code]obj.setVerson( usersArray[i].getVersion() );[/code]
then try to delete
[code]usersDao.delete(obj);[/code]
deletion is succesful however I cannot actually set version of obj with above obj.setVerson( usersArray[i].getVersion() );, I try to test it with
obj.setVerson( new Long(45) ); where actual version should be 0, I expect a objectstaleexception, however I see that delete operation resets the version to 0, so no Exception is thrown.
here is the usersDao.delete function
[code] public void delete( Object obj ) throws Exception
{
if ( obj==null )
return;
try{
getHibernateTemplate().delete( obj );
getHibernateTemplate().flush();
}catch( Exception e )
{
getHibernateTemplate().clear();
throw e;
}
}[/code]
At the hibernate logs, deletion is made according to version and key
[code]Hibernate: update public.users set version=?, password=?, enabled=? where username=? and version=?
Hibernate: delete from public.users where username=? and version=?[/code]
I think setting the obj version does not help for verisoning. Any ideas for versioning in delete operation for parent.
|