-->
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: Hibernate filters not working on collection
PostPosted: Tue Jun 26, 2012 2:36 am 
Newbie

Joined: Tue Jun 26, 2012 2:13 am
Posts: 2
I have been working on some upgrading which lead to some code using hibernate 3.6.8 instead of hibernate 3.2.7. This caused some problem in the code and after some debugging I found out the problem is in the Hibernate Filter. Here is the class with the filter annotations:

Code:
@Entity
@FilterDefs( {
      @FilterDef(name = "asOfFilter", parameters = {@ParamDef(name = "asOfDate", type = "timestamp")}),
      @FilterDef(name = "currentFilter", parameters = {})})
@Proxy(lazy = false)
   @javax.persistence.Table(
      name = "nmeIdt"
   )
public class NameIdt {

...

@org.hibernate.annotations.Filters({
    @org.hibernate.annotations.Filter(name = "asOfFilter", condition = "fromDate <= :asOfDate AND (currentFlag = 1 OR toDate > :asOfDate)"),
    @org.hibernate.annotations.Filter(name = "currentFilter", condition = "currentFlag = 1") })
@javax.persistence.OneToMany(mappedBy = "identity", fetch = javax.persistence.FetchType.EAGER, cascade = javax.persistence.CascadeType.ALL, targetEntity = NameVrs.class)
@Override
protected java.util.Set<Version<?>> getVersions() {
    return super.getVersions();
}
...
}


The Filters annotations are correctly added to the Version class, and I am certain that it is enabled. However turning on sql logging it is clear that the filter is not being applied to the query.

After some debugging into the Hibernate I found out the problem is in org.hibernate.persister.entity.AbstractEntityPersister, the FilterHelper this classes uses doesn't seem to pick up the Filters defined in my NameIdt class. This caused the AbstractEntityPersister->isAffectedByEnabledFilters() to return false. However if I put the Filter annotations on the class level instead of the collection property, it works.

To summarise, the FilterHelper does pick up the filters when its defined at the class level but it doesn't when its at the collection property. Is this suppose to happen and if so is there a work around for it? It will also be helpful if there is documentation on what the difference is betweeen when @Filter is attached at class and when its attached to the collection property.


Top
 Profile  
 
 Post subject: Re: Hibernate filters not working on collection
PostPosted: Wed Jun 27, 2012 6:25 pm 
Newbie

Joined: Tue Jun 26, 2012 2:13 am
Posts: 2
Really block by it, will appreciate help of any form~


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.