4 Replies Latest reply on Jun 30, 2006 5:30 PM by Rob Jellinghaus

    Can you @Filter a Seam @Entity?

    Rob Jellinghaus Novice

      Working with my Seam example, just ported to 1.0.1. Originally derived from the noejb example, which now became the Hibernate example.

      I'm trying to declare a @Filter on one of my @Entities:

      @Entity
      @Name("blogPost")
      @Filter(name="headOnly", condition="replicatedChangeset is null")
      public class BlogPostImpl implements BlogPost, Serializable {
       private Long id;
      ...
       @Id @GeneratedValue
       public Long getId()
       {
       return id;
       }
      ...
       private Changeset replicatedChangeset;
      
       /**
       * The changeset in which this object was created. Null for head objects; set for all
       * versioned copies.
       */
       @ManyToOne
       public Changeset getReplicatedChangeset ()
       {
       return replicatedChangeset;
       }
      ...
      }

      And I'm trying to use it in a query like this (yes, this is basically trying to make a version-tracking blog-posting system):
      new Script() {
      ...
       private Session database;
       @Override
       protected void updateModelValues()
       {
       database = (Session) Component.getInstance("database", true);
       assert database != null;
       }
      
       @Override
       protected void invokeApplication()
       {
      ...
       database.enableFilter("headOnly");
       List<BlogPostImpl> headBlogPosts = database.createQuery("from BlogPostImpl").list();
      ...
       }
      
       }.run();

      The exception I get is that the "headOnly" filter is not found:
      [testng] FAILED: com.robjsoftware.replog.test.ChangesetTest.testChangeset()
       [testng] org.hibernate.HibernateException: No such filter configured [headOnly]
       [testng] at org.hibernate.impl.SessionFactoryImpl.getFilterDefinition(SessionFactoryImpl.java:962)
       [testng] at org.hibernate.impl.SessionImpl.enableFilter(SessionImpl.java:1025)
       [testng] at com.robjsoftware.replog.test.ChangesetTest$4.invokeApplication(ChangesetTest.java:127)

      What am I missing? Is there any other magic I need to do to make @Filter work for a Seam @Entity? Are there any known examples of trying this? Should I even be expecting it to work? Should I try moving this to hibernate.cfg.xml (since I do *have* a hibernate.cfg.xml)?

      The Hibernate startup debug spam mentions "Binding entity from annotated class: com.robjsoftware.replog.domain.BlogPostImpl" but doesn't mention any filter annotations.

      Thanks very much -- I'm planning a bunch of aggressive weirdness with @Filters in this application, so it'll be a big bummer if Seam doesn't grok @Filter yet....
      Cheers,
      Rob