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.  [ 9 posts ] 
Author Message
 Post subject: Questions about Hibernate in Swing environment
PostPosted: Fri Feb 20, 2004 11:31 am 
Newbie

Joined: Thu Feb 12, 2004 10:02 am
Posts: 10
Location: Ghent, Belgium
I have a question.

We're writing Swing applications for data manipulation. We have a central "PersistenceManager", a wrapper round our current persistence layer (VBSF), that is being used throughout our program.

Code:
public interface IPersistenceManager
{
  public Connection getConnection() throws PersistenceException;
  public Object getId(Object obj) throws NullPointerException, PersistenceException;
  public Iterator iterate(Class type) throws PersistenceException, NullPointerException;
  public Iterator iterate(IQuery query) throws PersistenceException, NullPointerException;
  public List list(Class type) throws PersistenceException, NullPointerException;
  public List list(IQuery query) throws PersistenceException, NullPointerException;
  public Object load(Class type, Serializable id) throws PersistenceException, NullPointerException;
  public IQuery newQuery(Class type) throws NullPointerException;
  public void refresh(Object obj) throws NullPointerException, PersistenceException;
  public void remove(Object obj) throws DeleteFailedException, NullPointerException;
  public void remove(IQuery query) throws DeleteFailedException, NullPointerException;
  public void update(Object obj) throws PersistenceException, UpdateConflictException, NullPointerException;
}


We are looking to another persistence framework (and Hibernate is my favorite), so the plan is to replace our VBSF implementation with a Hibernate implementation.

Our program consists of "overview panels" (=grids) and "form panel" (= forms). A frame is composed from any combinations of these two components.

A typical scenario of a program is:
    1. the user opens an overviewframe (f.e. Customers)
    2. the user enters criteria to search a particular Customer
    3. the user double clicks on the Customer in the table to go to the form panel to modify the Customer
    4. he enters some data, and clicks the update button.

After reading the documentation on the hibernate website, I still have some questions:
    1. do we close the session after populating the overview and do we reopen it when the user clicks the update button?
    2. Or do we keep the session open for as long as the user is using the program?
    3. Or can we use the disconnect/reconnect methods in between?


The ideal solution would imply that throughout the program no extra instances are made in the different frames, we don't want to have two Customer objects pointing to the same row in the CustomerTable, because changes in one frame should be reflected in other frames where the same Customer instance is being used.

Thanks for your time,

Peter


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 12:04 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Some thoughts
The recommanded approch is to keep it a session alive for a business-tx-lifetime (in your case from search to end of update).

If you have not oo much users, then keep the session opened during your business-tx-lifetime. If not, then use the disconnected session.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 12:14 pm 
Newbie

Joined: Thu Feb 12, 2004 10:02 am
Posts: 10
Location: Ghent, Belgium
Thx for your reply,

I don't know if the "from search till update" is the business-tx-lifetime; the user may decide he doesn't want to update his changes at all (it is possible he just wanted to see the details of the Customer), so I think it could be a waste of resources (maybe I'm wrong here) to keep the session open.

The average number of users on our applications is from 10 to 30 users at the same time (all working on the same database).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 12:19 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Also check this page:

http://www.hibernate.org/Documentation/ ... ctionScope

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 1:45 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I'm not a DBA, but you probably can keep your sessions opened.
Beware that datas does not became dirty too fast, that's why session has to be not to long.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 3:49 am 
Newbie

Joined: Thu Feb 12, 2004 10:02 am
Posts: 10
Location: Ghent, Belgium
Thanks for the reply, it helped a lot.

So I guess it's ok if we do the following:

    1. get a Session instance
    2. Issue a query, show results in Swing JTable
    3. disconnect the session
    4. User clicks "Modify" -> open detail panel
    5. User makes changes, presses "Save"
    6. Reconnect the session
    7. update the object
    8. close or clear the session


Is it ok if we use the same session for the same user for the time the user keeps the application open, or would it be better if we get a new Session for each "master" frame we open (By master frame I mean an overview frame where the user can search for data)?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 3:03 am 
Newbie

Joined: Thu Feb 12, 2004 10:02 am
Posts: 10
Location: Ghent, Belgium
bump


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 5:15 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I session per user should be OK and consistent (user speaking)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 11:19 am 
Newbie

Joined: Thu Feb 12, 2004 10:02 am
Posts: 10
Location: Ghent, Belgium
thx


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