-->
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: Force Hibernate to deliver a partial graph
PostPosted: Tue Apr 06, 2004 5:52 am 
Beginner
Beginner

Joined: Mon Feb 23, 2004 1:17 pm
Posts: 28
Hey all,

I'm trying to build a 3 tier application with hiberante for persistence. I'm currently experimenting if I could use the objects I get from Hibernate directly in all the layers.

One thing I'm constantly bumping my head against is that hibernate instantiates lazy loaded collections from the object cache even if I explicitly request that collection to stay empty (outer-join=false, lazy=true).

Is there a way I can specify (in HQL or otherwise) a collection to stay empty while retireving the object? I tried adding the following to my sql statement:

select c from nl.s.g.customer as c left outer join projectSet as p where c.code='12345' and p.code = ''

p.code cannot be an empty string, so this should initialize c with an empty collection of projects. But then no records are returned.

If I just ask for

from nl.s.g.customer as c where c.code='12345'

I get a customer with a lazy loaded projectset which is empty most of the time unless one or more projects of this customer are in the cache, the objects in cache will be added to the Customer (eventhough those are NOT all the objects that belong in that collection).

So my question is:
How can I get an object from the database with an empty collection of child objects?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 06, 2004 11:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
One thing I'm constantly bumping my head against is that hibernate instantiates lazy loaded collections from the object cache even if I explicitly request that collection to stay empty (outer-join=false, lazy=true).


This is not the case in current CVS, and I don't think it is true of 2.1.2 either.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 4:50 am 
Beginner
Beginner

Joined: Mon Feb 23, 2004 1:17 pm
Posts: 28
I am using 2.1.2, but I tried again to be sure.

If I do the following:

create a customer
open session
save the customer
close session
open session
create a project with a name and the associated customer
save the project
create a project with a name and the associated customer
save the project
close session

open session
load the customer with lazy set of projects
close session
check number of projects: 2
toString the values of projects works

Debug log states: associating from cache for each project.

I found a way around this by using iunterceptors, they make sure now that the collection stays empty when it must,


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 5:37 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It is on cache, so you don't hit the DB to get your collection.
If you don't want to use second level cache, then remiove it from your mapping files.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 9:58 am 
Beginner
Beginner

Joined: Mon Feb 23, 2004 1:17 pm
Posts: 28
Ok, fixed this.

I do have a very similar problem. I've created an interceptor for a couple of types I'm using that are secured (with a custom security model). I'd like to be able to deny access to certain objects that are stored using hibernate based on properties in the class.

I've looked around and found a partial implementation of this on the wiki here.

But this doesn't seem to work as described. When doing a query to load a number of objects of a certain type (eg: From objectA) with at least one object that violated the check the whole list comes up empty. I'd like it to return all valid typed, except the objects that threw an exception during load.

I've read on the blog that there are plans to include something like this in hibernate 2.2/3.0. I looked at the source in the CVS, but couldn't find something liek this.

Is there a way this can be done? Or will I have to put the security exclusively in a higher layer?[/url]


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 2:27 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
For now put it at a higher level

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 5:36 am 
Beginner
Beginner

Joined: Mon Feb 23, 2004 1:17 pm
Posts: 28
Doing that now, but it a pain ;)

Is support for this planned? I think I read something like this on the blog a few weeks back, but can't seem to find it now.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 9:55 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://blog.hibernate.org/cgi-bin/blosxom.cgi/2004/04/02/

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 6:37 am 
Beginner
Beginner

Joined: Mon Feb 23, 2004 1:17 pm
Posts: 28
That's the one, glad to see it will come in the future, but it will unfortunately too late for me ;(. Ohh well, nice for the next project


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.