-->
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.  [ 7 posts ] 
Author Message
 Post subject: Hibernate in a desktop app
PostPosted: Mon Jun 14, 2004 2:19 am 
Beginner
Beginner

Joined: Thu Jun 10, 2004 6:52 am
Posts: 29
Hi guys. I would like to ask a question about using hibernate on the desktop. My question would be if there is on the desktop a pattern like ThreadLocal Session/OpenSessionInView on the server side ?

I mean if I use something like that on the desktop it would mean that I have a a single Session bound to the thread for the entire application lifetime. Which I suppose is not a very good practice. Or I should use a different thread for each "action" involving hibernate promoting responsive GUI in the same time ? Please share your thoughts, I could really use some design/architecture oppinions here, even few code sample(s) if I'm not becoming annoying :-)

Thanks. I would have posted it on the beginers thread but I really think it's an architecture question.[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 11:23 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I can remeber somewone doing a 1 session per desktop on a multithread client using sync on top of the Session.
Search the forum, it was discussed on a long thread.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 8:15 pm 
Beginner
Beginner

Joined: Fri Jan 16, 2004 3:22 pm
Posts: 26
hello all,

i have a question in the next scenario: there is a set of desktop applications distributed over a LAN, and a central database.

i'm tempted to use hibernate on each workstation to access the central database, however i dont know the implications of the per workstation caching of data.

is it possible to configure 'instances' of hibernate on both sides? i mean having hibernate running on each workstation accesing a central instance of hibernate on the database server??

hope made myself clear, :)

best regards
Gerardo.


Top
 Profile  
 
 Post subject: hibernate in a desktop app
PostPosted: Mon Jun 14, 2004 11:39 pm 
Beginner
Beginner

Joined: Thu Jun 10, 2004 6:52 am
Posts: 29
My question was not really about synchronization but about how can you make sure you have a session opened when fetching a lazy collection in a desktop app w/o using one single session opened for the entire lifetime of the application.

In a web app you have OpenSessionInViewFilter, I imagine one can do the same thing in a desktop app but then you should "simulate" how the server works, meaning a new thread for each action involving hibernate and for each new thread, a Session bounded in a ThreadLocal.

Thanks.


Top
 Profile  
 
 Post subject: Re: hibernate in a desktop app
PostPosted: Tue Jun 15, 2004 1:17 am 
Newbie

Joined: Fri Sep 26, 2003 4:29 pm
Posts: 16
Third attempt at posting - the session time out must be low, or I'm typing really slow tonight.

I've actually given up using the OpenSessionInView pattern.

I now consider the level of hydration of the object graph as part of the buisness logic and so write services that explicitly set this level. In this manner consumers of the services know what they are getting, and conceptually there is no difference between different methods of consuming or publishing the services. I've found this is the simplist solution, and one that avoids potential hidden lazy initialization errors from biting you.

dorel wrote:
My question was not really about synchronization but about how can you make sure you have a session opened when fetching a lazy collection in a desktop app w/o using one single session opened for the entire lifetime of the application.

In a web app you have OpenSessionInViewFilter, I imagine one can do the same thing in a desktop app but then you should "simulate" how the server works, meaning a new thread for each action involving hibernate and for each new thread, a Session bounded in a ThreadLocal.

Thanks.


Top
 Profile  
 
 Post subject: I've actually given up using the OpenSessionInView pattern.
PostPosted: Tue Jun 15, 2004 1:31 am 
Beginner
Beginner

Joined: Thu Jun 10, 2004 6:52 am
Posts: 29
meaning that for the getOrders() set of orders of a Customer object you have in the service layer a corresponding getOrdersForCustomer(customerId) method ? e.g. CustomerService.getOrdersForCustomer() ?

This is indeed a solution but I was wondering if there isn't another one that would allow me to fully exploit the lazy init collection feature of hibernate...


Top
 Profile  
 
 Post subject: Re: I've actually given up using the OpenSessionInView patte
PostPosted: Tue Jun 15, 2004 2:00 am 
Newbie

Joined: Fri Sep 26, 2003 4:29 pm
Posts: 16
Hmm, not sure I totally follow the example, but I'll try. If I needed a customer view that required the collection of orders, I would have a service method getCustomer(id) just as if using the OpenSessionInView. But, instead of relying on the OSIV pattern to lazy load he order objects, the service method getCustomer would ensure they are loaded. The actual method used can vary of course between lazy="false", fetch join in HQL, EAGER fetch mode in criteria or explicitly initialzing the orders collection. But, to the view/service consumer nothing changes.

dorel wrote:
meaning that for the getOrders() set of orders of a Customer object you have in the service layer a corresponding getOrdersForCustomer(customerId) method ? e.g. CustomerService.getOrdersForCustomer() ?

This is indeed a solution but I was wondering if there isn't another one that would allow me to fully exploit the lazy init collection feature of hibernate...


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