-->
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.  [ 5 posts ] 
Author Message
 Post subject: Filter at package level
PostPosted: Wed Aug 22, 2007 9:14 am 
Newbie

Joined: Thu Aug 16, 2007 10:53 am
Posts: 1
anyone please help me

How to have Filterdef at package level .I mean where exactly i mention it.


Top
 Profile  
 
 Post subject: Re: Filter at package level
PostPosted: Thu Jan 08, 2009 10:07 am 
Newbie

Joined: Thu Aug 21, 2008 5:32 pm
Posts: 4
Location: Slovakia
sai wrote:
How to have Filterdef at package level .I mean where exactly i mention it.


I'm not sure if you're using annotations or XML, but in case of annotations, this is done by placing your @FilterDefs into a package-info.java file (within your package) just before the "package com.foo.xyz" line.

I personally found this to be an ideal solution, but unfortunately can't make it work, and all my searches led to unanswered questions by developers having the same problem. I always get a HibernateException stating that there's "No such filter configured"...

When I place my @FilterDef annotations at class level, it all works, but you can't place multiple @FilterDefs to one class. Am I missing something with package-info.java? Was anyone able to make this work?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2009 1:32 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
The syntax for the package-info stuff is way whacky and if I let Idea reformat the class it jumbles the order.

Here's ours:

Code:

@FilterDefs({
    @FilterDef(name = ContextSet.CONTEXT_FILTER, parameters = {@ParamDef(name = ContextSet.CONTEXT, type = "com.x.app.context.ContextSet")}),
    @FilterDef(name = EnableBusinessUnitContextFiltersDatabaseOperation.BUSINESS_UNIT_FILTER_NAME, parameters = {@ParamDef(name = EnableBusinessUnitContextFiltersDatabaseOperation.MEMBER_PARAMETER, type = "java.lang.Long"), @ParamDef(name = EnableBusinessUnitContextFiltersDatabaseOperation.EFFECTIVE_DATE_PARAMETER, type = "java.util.Date")}),
    @FilterDef(name = EnablePeriodTypeContextFiltersDatabaseOperation.PERIOD_TYPE_FILTER_NAME, parameters = {@ParamDef(name = EnablePeriodTypeContextFiltersDatabaseOperation.PERIOD_TYPE_PARAMETER_NAME, type = "java.lang.String")}, defaultCondition = "PERIOD_TYPE = :" + EnablePeriodTypeContextFiltersDatabaseOperation.PERIOD_TYPE_PARAMETER_NAME),
    @FilterDef(name = EnableExpirableContextFiltersDatabaseOperation.EXPIRABLE_FILTER_NAME, parameters = {@ParamDef(name = EnableExpirableContextFiltersDatabaseOperation.EXPIRY_DATE_PARAMETER, type = "java.util.Date")}, defaultCondition = ":" + EnableExpirableContextFiltersDatabaseOperation.EXPIRY_DATE_PARAMETER + " <= EXPIRY_DATE"),
    @FilterDef(name = EnableVersionPeriodContextFiltersDatabaseOperation.MOST_EFFECTIVE_VERSION_FILTER_NAME, parameters = {@ParamDef(name = EnableVersionPeriodContextFiltersDatabaseOperation.VERSION_START_DATE_PARAMETER, type = "java.util.Date"), @ParamDef(name = EnableVersionPeriodContextFiltersDatabaseOperation.VERSION_END_DATE_PARAMETER, type = "java.util.Date")}),
    @FilterDef(name = EnableVersionPeriodContextFiltersDatabaseOperation.VERSION_FILTER_NAME, parameters = {@ParamDef(name = EnableVersionPeriodContextFiltersDatabaseOperation.VERSION_START_DATE_PARAMETER, type = "java.util.Date"), @ParamDef(name = EnableVersionPeriodContextFiltersDatabaseOperation.VERSION_END_DATE_PARAMETER, type = "java.util.Date")}, defaultCondition = ":" + EnableVersionPeriodContextFiltersDatabaseOperation.VERSION_END_DATE_PARAMETER + " >= VERSION_START_DATE"),
    @FilterDef(name = EnableEffectivePeriodContextFiltersDatabaseOperation.DATE_EFFECTIVE_FILTER_NAME, parameters = {@ParamDef(name = EnableEffectivePeriodContextFiltersDatabaseOperation.EFFECTIVE_DATE_PARAMETER, type = "java.util.Date"), @ParamDef(name = EnableEffectivePeriodContextFiltersDatabaseOperation.INACTIVE_DATE_PARAMETER, type = "java.util.Date")}, defaultCondition = ":" + EnableEffectivePeriodContextFiltersDatabaseOperation.EFFECTIVE_DATE_PARAMETER + " <= INACTIVE_DATE AND :" + EnableEffectivePeriodContextFiltersDatabaseOperation.INACTIVE_DATE_PARAMETER + " >= EFFECTIVE_DATE AND INACTIVE_DATE > EFFECTIVE_DATE"),
    @FilterDef(name = EnablePropertyContextFiltersDatabaseOperation.PROPERTY_BOUND_FILTER_NAME, parameters = {@ParamDef(name = EnablePropertyContextFiltersDatabaseOperation.LOCATION_ID_PARAMETER, type = "java.lang.Long"), @ParamDef(name = EnableEffectivePeriodContextFiltersDatabaseOperation.EFFECTIVE_DATE_PARAMETER, type = "java.util.Date"), @ParamDef(name = EnableEffectivePeriodContextFiltersDatabaseOperation.INACTIVE_DATE_PARAMETER, type = "java.util.Date")}),
    @FilterDef(name = EnableExportContextFiltersDatabaseOperation.EXPORT_FILTER_NAME, parameters = {@ParamDef(name = EnableExportContextFiltersDatabaseOperation.EXPORT_TASK_PARAMETER, type = "java.lang.Long")}, defaultCondition = "not exists (select o.object_uuid from object_export o, workflow_event_task wet, workflow_task_defn wtd  where o.object_uuid = uuid and o.state = 'PASS' and o.workflow_event_task_id = wet.workflow_event_task_id and wet.workflow_task_id = wtd.workflow_task_id and wtd.workflow_task_id = :" + EnableExportContextFiltersDatabaseOperation.EXPORT_TASK_PARAMETER + " and o.create_date = (select max(o2.create_date) from object_export o2 where o2.object_uuid =o.object_uuid))")
        })

@GenericGenerator(name = "uuid-generator", strategy = "uuid") package com.x.app.hibernate;

import com.x.app.context.ContextSet;
import com.x.app.database.*;
import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.FilterDefs;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.ParamDef;


_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2009 2:13 pm 
Newbie

Joined: Thu Aug 21, 2008 5:32 pm
Posts: 4
Location: Slovakia
VampBoy wrote:
The syntax for the package-info stuff is way whacky and if I let Idea reformat the class it jumbles the order.


Thank you for posting your example! In the meantime, I was able to find out why I was getting the "No such filter" error - I completely forgot about adding the <mapping package="com.foo.xyz" /> into hibernate.cfg.xml!!! Well - a silly mistake. ;)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2009 2:48 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Yep, I meant to post that as well but I got distracted by shiny objects.

You have to do the same sort of thing in an annotation config.

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


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