[hibernate-issues] [Hibernate-JIRA] Closed: (HHH-4288) Filters on collections are ignored
Sharath Reddy (JIRA)
noreply at atlassian.com
Fri Oct 23 13:13:12 EDT 2009
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-4288?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Sharath Reddy closed HHH-4288.
------------------------------
Resolution: Cannot Reproduce
Hi,
I wrote a test case very similar to the one you uploaded, and added it to our test suite. It runs fine against trunk.
In the test that you uploaded, you dont need to define the @Filter again in the Narrative class, since it is already defined in Topic. Nevertheless, it should still work fine.
> Filters on collections are ignored
> ----------------------------------
>
> Key: HHH-4288
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4288
> Project: Hibernate Core
> Issue Type: Bug
> Components: annotations
> Environment: Hibernate 3.2; MySql 5.0.51a; Java 1.6
> Stand-alone app - no server
> Reporter: Eric Ford
>
> I have two classes: Topic and Narrative. A topic has one-to-many narratives. I want to impose a filter such that only narratives with a particular state value are returned when I look up a topic.
> @Entity
> public class Topic
> {
> //unrelated attributes not shown
> private Set<Narrative> narratives = new HashSet<Narrative>();
> @OneToMany(mappedBy="topic")
> @Filter(name="byState", condition=":state = state")
> public Set<Narrative> getNarratives()
> {
> return narratives;
> }
> public void setNarratives(Set<Narrative> narratives)
> {
> this.narratives = narratives;
> }
> }
> @Entity
> @FilterDef(name="byState", defaultCondition=":state = state",
> parameters=@ParamDef(name="state",type="string"))
> @Filter(name="byState", condition=":state = state")
> public class Narrative
> {
> private String content = "";
> private String state = "";
> private Topic topic = null;
> //getters and setters not shown
> }
> @Test
> public void FindSystemById(){
> //for this test, the indicated topic has two narratives,
> //one is "published" and the other is "draft"
> session.enableFilter("byState").setParameter("state", "published");
> Topic result = null;
> result = TopicDao.findById(new Long(1), noLock); //
> assertNotNull(result); //this always passes, as expected
> System.out.println(result.getNarratives().size(); //this always returns 2
> assertTrue(result.getNarratives().size() == 1); //this always fails, obviously
> }
> The sql code does not show the filter being applied when fetching the collection.
> I've tried variations including adding the @Filter annotation to the getNarratives() method only and adding the @Filter annotation to the Narrative class only. I've also tried putting the @FilterDef annotation on the Topic class instead of the Narrative class. None of these variations has given the desired result of only one narrative returned from the getNarratives() method. I am coding with Java 1.6, Hibernate 3.2, and MySql 5.0.51a using Eclipse 3.4 and testing with JUnit 4.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list