1 Reply Latest reply on Aug 28, 2009 12:22 AM by Arbi Sookazian

    entities with dependencies

    Lukasz Rozek Newbie

      hi guys


      Can entities act as seam components ?? When I execute any query against entity manager, I'd like to get entity with dependencies injected by seam. i.e my entity would look like below


      @Entity
      public class User {
      
         fields...
      
         @In(create = true)
         private SomeComponent someComponent;
      
         business methods using dependencies...
      
         setters / getters...   
      }
      



      thx for replies

        • 1. Re: entities with dependencies
          Arbi Sookazian Master

          Yes, an entity can be a Seam component (jut add @Name to the class).  There's an example early on in SiA book (using entity class as backing bean in JSF page).


          No, you can't inject anything into an entity class, even if it's a Seam component.  I actually tried this recently and got a NPE.


          e.g.


          @Name("foo")
          @Entity
          @Table(name = "Foo")
          public class Foo{
               
               @In(create=true)
               private FacesMessages fm;
          
               private String bar;
          
               Foo(String bar){
                   this.bar = bar;
                   fm.add("test");   // <-- NPE here!
               }
          
               public void setBar(String bar){
                    this.bar = bar;
               }
          
               public String getBar(){
                    return bar;
               }
          }



          IIRC the bijection interceptors do not work on entity classes.  I'm not sure where in the Seam core codebase it checks for the type of component prior to doing interceptions...