-->
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: Initialization of Collections
PostPosted: Mon Aug 25, 2008 3:58 pm 
Newbie

Joined: Fri Jun 20, 2008 2:16 pm
Posts: 6
Hello All,

I am using Hibernate 3.2.6
database: Postgres 8.2

We are using Hibernate in our 2-tier architecture ( A Swing App). And, my concern is initialization of Maps into Memory.
I am using a Single-Session-perConversation pattern.

A parent object has a huge collection (100,000+), and the first time I do a map.put on the PersistentMap, hibernate loads all the object into memory. To avoid this, I am using lazy = 'extra' property, where instead of initializing all the collection objects at once, it creates and queues direct SQL commands.

THE ISSUE: multi-user accessibility.
If I start 2 apps against the same database and create a new object into a (lazy='extra') collection in the 1st app, then do the same in 2nd app, the 2nd app hangs until I commit the transaction in the 1st app. It seems like a lock is being held.
I am using Hibernate's default locking behavior.

Is this the expected behavior, any alternative approach?

Thanks

-kashyup


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 25, 2008 6:39 pm 
Newbie

Joined: Thu May 31, 2007 3:27 am
Posts: 11
Do you really need a map on the parent? You surely don't need to have 100,00 objects in memory, moreover that you prevent this using the "lazy=extra" attribute, so why bothers trying to map it as a huge collection?

Collections and Maps are a "feature" of hibernate, see:

http://blog.hibernate.org/1395.lace

You could use an hql query to retrieve a particular object and modify this object directly instead of going through a map.

You could design an Helper class or a DAO like this that will behave as you want to instead of using a "Map":
Code:
public class ParentDAO{
 
  private Parent parent;
  private Session session;

  public ParentDAO(Session session,Parent parent){
     this.parent=parent;
  }

  public void put(String key,Child child){
     child.setKey(key);
     child.setParent(parent);
     session.save(child);
  }

  public Child get(String key){
     return session.createHqlQuery(
          " select child from Child child"+
          " where child.parent=:parent and child.key=:key"    )
              .setParameter("parent",parent)
              .setParameter("key",key)
              .uniqueResult();
  }
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 26, 2008 2:44 pm 
Newbie

Joined: Fri Jun 20, 2008 2:16 pm
Posts: 6
thanks!
This does gives me an alternate approach, and I could see the PersistentMap issue not happening here.


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.