-->
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: Using Hibernate in desktop app w/ Swing GUI
PostPosted: Tue Jul 25, 2006 4:15 pm 
Newbie

Joined: Mon Jul 24, 2006 3:21 pm
Posts: 14
I realize that Swing is a presentation framework and Hibernate is an ORM technology for simplifying the data layer. I realize that the two have little to do with each other. Still I have a question that I can't find a straightforward answer to.

I need to render an object, say a Thing object. When the user clicks on the visual representation of the Thing object, I need to call myThing.getContents() which should return a Set of persistent objects. I want the set to be lazy loaded. Therefore, when the user clicks on myThing, I need to attach myThing to a session (using
Code:
Session.lock(myThing,LockMode.NONE)
I assume), then call getContents(), then detach, etc.

Is there a good pattern to be used here? The app I'm working with is too far along to go back and put in an AOP container or something cool like that so that I can use interceptors or something of that sort.

Is there a simple way to manage Hibernate Sessions so they are available without putting any knowledge of session management into any of my Swing code?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 25, 2006 4:32 pm 
Beginner
Beginner

Joined: Tue Jan 06, 2004 4:51 pm
Posts: 48
In general, you can put all your hibernate code in a control class so that it does not appear in your Swing code.

In your example, I would have your getContents() method call some control class' (maybe static) getContents(myThing), which would do all the code you posted and return the collection.

The advantage of this is, of course, if you choose another ORM you only need to change the control class.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 25, 2006 4:43 pm 
Newbie

Joined: Mon Jul 24, 2006 3:21 pm
Posts: 14
dtam wrote:
In your example, I would have your getContents() method call some control class' (maybe static) getContents(myThing), which would do all the code you posted and return the collection.


I previously tried something like this, but ran into problems. When a call to Session.lock() occurred, Hibernate tried to validate the state of the object by calling a bunch of it's getters. This resulted in a call to getContents() which then called Session.lock() and on and on...


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.