-->
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: Hibernate 3 filters for a object graph loading
PostPosted: Tue Aug 30, 2005 11:48 am 
Beginner
Beginner

Joined: Mon Sep 22, 2003 5:18 am
Posts: 28
Suppose we have the following object graph:
Code:
publc Obj{
   property long id;
   property NestedObj1 obj1;
   property NextedObj2 obj2;
...
   property boolean deletedFlag;
}

publc NestedObj1{
   property long id;
   property String name;
  ...
   property boolean deletedFlag;
}

publc NestedObj2{
   property long id;
   property String name;
  ...
   property boolean deletedFlag;
}

Nested objects mapped as 'many-to-one'
I have a Filter called 'myFilter' as follows:
Code:
<filter-def name="myFilter">
</filter-def>


Each mapping for each object has the following element:
Code:
<filter name="myFilter" condition="deleted_FLAG = 'Y'"/>   


before running hql, i perform session.enableFilter("myFilter").

Filter is applied to selection, i.e. appropriate where clause prepended, when I'm trying to load object. And it is applied only to that object which is selected.
How can I propagate the filtering for each nested object as well when loading Obj, which contains NestedObj1, NestedObj2, so that only those NestedObj1 and NestedObj2 loaded that meet similar filter criteria. (basicly, I want to load not logically deleted object and its not logically deleted nested objects)



[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 30, 2005 5:25 pm 
Beginner
Beginner

Joined: Mon Sep 22, 2003 5:18 am
Posts: 28
Does hibernate apply filter to nested object, if it is configured in its mapping file.
I have a Child, and filter element, this filter is correctly applied to it when i query the Child object.
This Child object is also could be mapped to some Parent object. Parent object may have multiple childs. I want to load Parent and only those its Child objects, that matches the Childs' filter condition.
It doesnt work by default. How to make it work ?


Top
 Profile  
 
 Post subject: Hibernate 3 filters for a object graph loading
PostPosted: Sun Sep 11, 2005 10:16 am 
Newbie

Joined: Thu Sep 08, 2005 3:49 pm
Posts: 3
Location: Frankfurt, Germany
Hi lovkiys !

I seem to have the same (or a similar) problem.
I discovered your post while searching for a solution but unfortunatly nobody
has answered your post yet. I've created a new post today describing my problem under the title "Filter not applied to sub-level elements".
Maybe an answer there will also help you (or vice versa).

Joak


Top
 Profile  
 
 Post subject: post filtering solution
PostPosted: Fri Aug 04, 2006 5:46 pm 
Newbie

Joined: Fri Aug 04, 2006 5:39 pm
Posts: 2
Hi, I have the same problem and the only solution i found was a post load filtering. When I load an object graph I recursivelly using reflection remove (in fact replace by fake objects) objects without a read right. Here's my code which you can inspire on.

protected Object secure(Object object, Vector visitedOids) {
try {
if (object == null) {
return null;
}
if (object instanceof Vertex) {
Vertex vertex = (Vertex) object;

visitedOids.add(vertex.getOid());
BeanInfo beanInfo = Introspector.getBeanInfo(vertex.getClass());

PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();

for (PropertyDescriptor pDesc: propertyDescriptors) {
if (isOfClass(Vertex.class, pDesc.getPropertyType()) && !isOfClass(FakeVertex.class, pDesc.getPropertyType())) {
Method readMethod = pDesc.getReadMethod();
Vertex innerVertex = (Vertex) readMethod.invoke(vertex, (Object[]) null);
if (innerVertex != null && !visitedOids.contains(innerVertex.getOid())) {
innerVertex = (Vertex) secure(innerVertex, visitedOids);
if (innerVertex instanceof FakeVertex) {
Method writeMethod = pDesc.getWriteMethod();
writeMethod.invoke(vertex, new Object[] {innerVertex});
}
}
} else if (isOfClass(Collection.class, pDesc.getPropertyType())) {
Method readMethod = pDesc.getReadMethod();
Collection collection = (Collection) readMethod.invoke(vertex, (Object[]) null);
if (collection != null && !visitedOids.contains(collection)) {

secure(collection, visitedOids);
}
}
}
if (!isReadGranted(vertex.getAcl())) {
return new FakeVertex(vertex);
}
return vertex;
} else if (object instanceof Collection) {
//doesnt' solve collection in collection
Collection collection = (Collection) object;
visitedOids.add(collection);

for (Iterator iterator = collection.iterator(); iterator.hasNext();) {
Object o = iterator.next();
if (!(o instanceof Vertex)) {
continue;
}
Vertex vertex = (Vertex) o;
Vertex securedVertex = (Vertex) secure(vertex, visitedOids);
if (securedVertex instanceof FakeVertex) {
iterator.remove();
}
}
return collection;
} else {
return object;
}

} catch (Exception e) {
logger.error(e);
throw new RuntimeException("Cannot secure vertex.", e);
}
}


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.