-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Requesting help concering delete function
PostPosted: Tue May 08, 2007 8:40 am 
Beginner
Beginner

Joined: Tue May 08, 2007 8:26 am
Posts: 21
Hello,

I have a short problem concerning the delete function on a webbased application.

Example code:
Code:

...
User user = new User( 1);
Machine machine = new Machine( 5);
UserMachine userMachine = new UserMachine( user, machine);
deleteObject( userMachine)
...

function deleteObject( Object object)
{
   // Simplified
   Session session =  InitSessionFactory.getSessionFactory().getCurrentSession();
   Transaction transaction = session.beginTransaction();
   session.delete( object);
   transaction.commit();
}

...


Now this works fine and all, but see the current situation:

On the website there is a handy shortcut link to quickly delete the coupling between a user and a machine.
This is done by creating the user & machine objects with the appropriate user id and machine id, these two objects are put into another object (the many-to-many relationship table, why this is manually done is because the many-to-many table has some extra columns other then the two foreign keys ) and sending this to the delete function above (as you can see in the example code).
This works fine, the entry inside the UserMachine table is deleted right.

But now when you refresh the page (with the same user id and machine id), hibernate does not give an exception.
I have checked the log files and it does not execute the delete query at all (even though i call it).
So it seems hibernate checks something locally so it knows it's already deleted and thus not executing the query.
But I want it to throw an exception so I can block off someone F5'ing with the exception other then creating extra code to retrieve the values first and check if they match.

Is there anything wrong with my configuration or something else? (caching is not enabled, as far as i know)

Thank you

edit2:
When I delete a user, and I F5 that after that, I will get an unexpected row count (from hibernate), which I can catch and act appropriate on.
This is how I want it to work with userMachine as well.
So it seems there is a mapping mistake or something that i am doing wrong.

edit1:
Smaller made hibernate mapping files of usermachine user and machine:

User:
Code:
<class name="User" table="users">
   <id name="userId" column="users_id" type="int">
      <generator class="sequence">
         <param name="sequence">users_users_id_seq</param>
      </generator>
   </id>

   <property name="userName" column="users_name" type="string" />
   <property name="userPassword" column="users_password" type="string" />

        <!-- more properties -->   

   <set name="userMachines" cascade="all" lazy="false" inverse="true" >
       <key column="users_id" />
       <one-to-many class="UserMachine" />
   </set>
</class>


Machine:
Code:
<class name="Machine" table="machine">
   <id name="machineId" column="machine_id" type="int">
      <generator class="sequence">
         <param name="sequence">machine_machine_id_seq</param>
      </generator>
   </id>

   <property name="machineSerialNumber" column="machine_serialnumber" type="string" />

        <!-- more properties -->   

   <set name="userMachines" cascade="all" lazy="false" inverse="true" >
       <key column="machine_id" />
       <one-to-many class="UserMachine" />
   </set>
</class>


UserMachine:
Code:
<class name="UserMachine" table="usersmachine">
   <composite-id>
       <key-many-to-one name="user" class="User" column="users_id" lazy="false" />
       <key-many-to-one name="machine" class="Machine" column="machine_id" lazy="false" />
   </composite-id>
   
       <!-- properties -->
</class>


Last edited by radic on Tue May 08, 2007 9:15 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue May 08, 2007 9:03 am 
Senior
Senior

Joined: Sat Apr 21, 2007 11:01 pm
Posts: 144
Try flushing your session. Really though I think this is more of a web app question than a Hibernate one. Wouldn't it be better to not have your app try and redo the delete if you F5?

_________________
Everytime you get an answer to your question without giving credit; god kills a kitten. :(


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 08, 2007 9:10 am 
Beginner
Beginner

Joined: Tue May 08, 2007 8:26 am
Posts: 21
adamgibbons wrote:
Try flushing your session. Really though I think this is more of a web app question than a Hibernate one. Wouldn't it be better to not have your app try and redo the delete if you F5?


Well I could do that, but I rather leave this to a lower layer.
Plus it is alot more work (how do you determine when F5 has happened, you will have to create an extra query to the DB to find the corresponding user and machine if it exists) trying to prevent the F5 then just catching an exception and showing a nice error page.

I have alot of objects that i need to delete on the website, and this is the only one (so far) that does not work.
When I delete a user for example, and I F5 that after that, I will get an unexpected row count, which I can catch and act appropriate on.
I realize I forgot that in my main post, will add that now because it's pretty important.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.