-->
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.  [ 2 posts ] 
Author Message
 Post subject: Simple Collection use
PostPosted: Sat Apr 23, 2005 10:38 pm 
Beginner
Beginner

Joined: Wed Apr 20, 2005 9:30 am
Posts: 39
Hibernate version:
3.0.1
Name and version of the database you are using:
SQL Server 2000 sp3

I've read through the documentation many times and now also have several books on the subject just to fill things out. My question is this as I've not seen it addressed anywhere just yet:

I have a number of tables which are essentially lists of Things, and quite often, all I need to do is drop the collection of Things into a Velocity template for rendering in order for some poor soul to make a selection in a web page somewhere. Now... using the mapping files, I have options to cache maps, lists, bags, etc... but, all the documentation related to M2M or O2M mapings are of other objects within the Thing type(s).

The question is... do I have a way through session.get() or session.load() [which would let me use a cached collection] to only access the basic collections or do I always have to use session.list() which seems to not ever get cached?

It seems to me that session.get(Thing.class, 0) or whatever identifier will retrieve that object and it's related maps, when all I need is a collection of Things.

Thoughts?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 25, 2005 5:40 pm 
Regular
Regular

Joined: Mon Jul 26, 2004 2:28 pm
Posts: 86
Location: Pensacola, Florida
I tend to access collections in one of two ways:

1. Create a <set> or <list> with a <one-to-many> association
2. Use session.createCriteria( Object.class ).add( ... ).list( )

The latter can be cached (I believe) by calling setCacheable( true ) like so:

session.createCriteria( Object.class ).setCacheable( true ).add( ... ).list( );

However, I think it's only cached for the precise query that is executed (if you don't have any filter expressions then that's a non-issue). To simply load the list of all things in a given table:

session.createCriteria( Thing.class ).setCacheable( true ).list( );

Should do it and cache the results. Criteria queries also have the trait of loading objects with implicit fetch semantics, meaning outer-joins are used to load many-one and one-one associations (where allowed), which I find very useful.

- Jesse


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