-->
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.  [ 6 posts ] 
Author Message
 Post subject: DWR with Hibernate
PostPosted: Wed Dec 17, 2008 12:20 pm 
Beginner
Beginner

Joined: Wed Dec 17, 2008 12:10 pm
Posts: 47
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.3.1

I'm building a Dojo app with DWR and Hibernate. I am having a hard time finding anyone else doing anything similar so this has been difficult. Everyone else seems to be using Spring as well...I don't see the point. However, I am having session management woes. For instance, I am removing an object from a collection with one ajax call, then executing another call which goes and gets the collection. When the collection is retrieved, the old object still exists even though it was previously removed, saved, and committed! Is it worth getting spring up and running just for hibernate session management?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2008 9:30 pm 
Newbie

Joined: Wed Dec 17, 2008 6:35 pm
Posts: 11
Are you removing an item from a set and doing a cascading update on the parent object? If so, I think you would need to explicitly delete the item in the Set and remove the item from the set. I'm assuming you have detached instances of these objects (you say you have committed and the transaction is flushed and closed on commit i believe).


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Wed Dec 17, 2008 9:43 pm 
Beginner
Beginner

Joined: Wed Dec 17, 2008 12:10 pm
Posts: 47
Thanks for the response. I have tried both ways, letting hibernate manage the deleting of the child items and also deleting them manually. Here's the scenario:

AJAX Request to delete the child item from the collection.

Another AJAX request to get the updated list of child items.

These AJAX requests are definitely executed one after the other. I have javascript that manages the requests so that they do not overlap. The reason I'm doing this is when they overlap, the second call gets "Session is closed!" because the first request commited the transaction (closing the session) while the second request was still executing.

I'm trying to use the OpenSessionInView pattern, which seems to have resolved this problem...but others have arisen. I have a servlet which serves up images. The images are loaded via plain old HTML <img> tags. Because of this, I have no control over when the images are loaded (and the servlets are executing). The servlets seem to be having the same problem (overlapping sessions, being closed in the middle of another while running).

My question is...how the heck can I manage my sessions in a manner that works for an AJAX application??


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2008 10:48 pm 
Newbie

Joined: Wed Dec 17, 2008 6:35 pm
Posts: 11
I'm a big fan of keeping the session open for the duration of the request (I'm assuming you have a servlet filter that start the transaction at the beginning of the request and closes it at the end). I'm not sure what is going on with this servlet for images though. Are these images blobs in the same database? If so are you using the same session as you are for the other stuff?

Your session factory really just maintains a map of sessions with the key being the local thread (so multiple have their own session and aren't colliding). If you are committing though your session will get closed and maybe your other servlet is still needing the session. Also, I think rollbacks will close your session.

If so do you need to be using the same session as the other one? Could you have a different session factory for the images.

Maybe I'm not understanding correctly.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2008 12:23 am 
Regular
Regular

Joined: Wed Apr 25, 2007 11:44 pm
Posts: 59
try to keep the ajax calls sync

or

get an updated version of dwr and make use of callbacks for getting a fresh collection providing that the delete operation was successfully been performed


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2008 9:30 am 
Beginner
Beginner

Joined: Wed Dec 17, 2008 12:10 pm
Posts: 47
Hey Tim,

I ended up manually opening a stateless session for the image servlet. Yes, I was storing images in a blob field and serving them up in the servlet. It seems to be working fine now. One odd thing is every now and then I was getting an exception "Collection belongs to another session" or something along those lines. I think that has been cleared up, but I don't want to speak too soon.

MSJ4u: My AJAX calls are synchronous, I created a mechanism to make sure the calls do not get made at the same time (maybe I should call it SJAX). Also, I was using the DWR callback to load the fresh collection, but for some reason it was returning stale data. Sometimes, it was returning uncommitted data somehow. Basically, my code previously was doing this:

Delete an image, reorganize the image numbering (so they are sequential even after a delete) then save the parent object (which cascades to the images).

I changed the code to do this:

Delete the image, save the parent. Re-organize the images, save the parent. This seems to have fixed the stale data issue, although I'm not sure why.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.