-->
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.  [ 4 posts ] 
Author Message
 Post subject: session.map();
PostPosted: Thu Dec 01, 2005 11:01 am 
Beginner
Beginner

Joined: Wed Feb 23, 2005 10:37 am
Posts: 29
Hi,

Is there any possibility to map() instead of list?
What I need to have in the resulting Map is the Object with its primary key and the object itself for tables having primary key, not a composite primary key.

I used to do it in JDBC easily but when I started using Hibernate I always have to iterate the list and put the object with its primary key.

Thanks for any reply.

-N


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 3:27 pm 
Contributor
Contributor

Joined: Thu Nov 06, 2003 9:49 pm
Posts: 104
Location: New York, NY
So, you want a Map of object by their primary key eh?

You are probably using the map to find objects by their id, right? You should think about re-writing your code so you don't use Map to look up objects by their ids. This is redundant because Session.get() does this, and so should your DAOs. Map just isn't the right way to do this. I've had to refactor a lot of code that does things this way... it's really not a good idea.


Top
 Profile  
 
 Post subject: caching
PostPosted: Fri Dec 02, 2005 4:54 am 
Beginner
Beginner

Joined: Wed Feb 23, 2005 10:37 am
Posts: 29
Well, we cache the objects retrieved from the DB. So the code consults the cache first and if there is a miss then it quieries the db or executes session.get().
The thing is that we dont use hibernate's second level cache to cache objects. We have our own caching technique (implemented for local simple caches and in distributed caching environment, i.e. tangosol). Thats why I need to map objects since I don't have too many rows in DB, I thought it would be wise to fetch them all at once.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 02, 2005 7:33 am 
Newbie

Joined: Wed Aug 25, 2004 5:00 am
Posts: 4
I think you should use the built-in cache of hibernate.
If you are going to cache the objects yourself, you'll have to remember to attach the objects to a new session, if the old one was closed. Also, updates from the DB have to be managed (cache timeout).
Hibernate already does that for you for you.


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