-->
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: @Filter vs @Where
PostPosted: Thu Feb 05, 2009 4:06 pm 
Newbie

Joined: Tue Feb 03, 2009 7:26 pm
Posts: 10
Correct me if I am wrong.

I gather @Where can be used at class level for a permanent where for all fetches. I mean something along the lines of
@Entity
@Where(condition = "not expiryDate is null"
public class Item
{
@Id
@Column
Integer id;

@Column(name = "EXPIRY_DATE")
Date expiryDate
}

@Filter can be used at field or method level to filter a Collection with @FilterDef for same defined at class level. This filter can enabled and disable and also the parameter values be changes during runtime.

@FilterDef(name="expiryDateFilter", @ParamDef(name="now", type="java.util.Date"))
public class Inventory
{
@Id
@Column
Integer id;

@Filter(name="expiryDateFilter", condition = "expiryDate > :now")
Collection<Item> items;
}

enable/disable the filter using hibernate session. This is my understanding on these features.

1. But I am unable to get @Where working. Could someone please provide a working sample ?
2. Is the filter defined by @Filter used during the fetch from database or later when the collection is accessed using getItems() in this example ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2009 5:42 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Both @Where and @Filter can be used on classes and collections.

Quote:
But I am unable to get @Where working.


The example you have seems to use HQL in the condition. You must use SQL both in @Where and @Filter.

Quote:
Is the filter defined by @Filter used during the fetch from database or later when the collection is accessed using getItems() in this example ?


It is used in the database query that fetches the items, but if you collection is lazy this usually doesn't happen until you access the collection. Eg. getItems().iterator(), getItems().add(...), etc.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2009 7:13 pm 
Newbie

Joined: Tue Feb 03, 2009 7:26 pm
Posts: 10
Though I used HQL in this example, my intent was SQL. Thanks for pointing it out.

Could I still get a working sample of @Where ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2009 7:29 pm 
Newbie

Joined: Tue Feb 03, 2009 7:26 pm
Posts: 10
@Where(clause = "not upper(USERNAME) like 'SYS%'")

seems to work for me.

Thanks nordborg.


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.