-->
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: design pattern for a read only object
PostPosted: Sat Sep 25, 2004 9:21 pm 
Beginner
Beginner

Joined: Sun Dec 14, 2003 10:47 am
Posts: 23
I have the following Hibernate persisted objects. Note: PersistentObject takes care of common persisting chores (uid, discriminator, version, timestamps)...

class Language extends PersistentObject {
HashMap entries_; // one-to-many hash map of entry key and entry instance o

}


class LanguageEntry extends PersistentObject {
String key;
String translation;
Language owner; // many-to-one
}


I have other classes that reference a Language.

class Group extends PersistentObject {
...
Language defaultLanguage_;
...

}


class User extends PersistentObject {
...
Language language_;
...

}


The issue is with each web request a new Language and LanguageEntries are loaded. This is causing scaling issues due to the 1000-10000 entries for a language. I would like to make Language and LanguageEntry be shared between sessions since it is read-only anyway (well for the purposes of this discussion it is).

Is this possible in Hibernate?

I know I can do it by not having Language and LanguageEntry be loaded in the same session as Group and User. I.e. have a global session that loads Language and :anguageEntries once. Then in the session for Group and User load the Language using a LanguageType that uses the Global session to load the Language and Entries if they aren't loaded already.

I would like to avoid this since there is a substantial framework in place around Hibernate that unfortuntealy would not Support separate sessions and configs that this would require.

Any help is appreciated...

regards,
Fizzy


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 26, 2004 9:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Use the second level cache


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 26, 2004 10:22 am 
Beginner
Beginner

Joined: Sun Dec 14, 2003 10:47 am
Posts: 23
To make sure I have this correctly..

I can use the EHCache provider (or one of the others)

add a

<cache usage='nonstrict-read-write'/>
or
<cache usage='read-only'/>

For all the classes I want cached at the SessionFactory/JVM level.

The remaining classes, the ones without the <cache> tag will get cached at the session level only.


If that is the case, which I think it is ;-) then that will do wonderfully and elegant too boot.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 26, 2004 10:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
right


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 26, 2004 10:37 am 
Beginner
Beginner

Joined: Sun Dec 14, 2003 10:47 am
Posts: 23
Woohoo!!!! Thanks Michael.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 26, 2004 10:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Remember to add cache tags to your associations, too.


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.