4 Replies Latest reply on Oct 11, 2005 5:50 AM by gavin.king

    bijection for entity beans

    patrick_ibg

      I read from the docs that @Entity components cannot take part in bijection. Is this by design, or an EJB restriction? I can see a use case for allowing bijection for entities:

      @Entity
      @Name ("user")
      @Scope (SESSION)
      public class User {
       ...
      }
      
      
      @Entity (AccessType.FIELD)
      @Name ("someObject")
      public class SomeObject {
      
      @Transient
      @In
      private User user ;
      
      @ManyToOne
      private User updater ;
      
      @Basic
      private Date updateTime ;
      
      @PreUpdate
      public void onPreUpdate () {
       this.updater = user ;
       this.updateTime = new Date () ;
      }
      
      }
      


        • 1. Re: bijection for entity beans
          gavin.king

          Yes, this is by design, the domain model should not be dependent upon application logic, because the domain model is shared and changes much less often.

          Also, entity beans are often instantiated by the application instead of by Seam, and Seam can not then intercept them.

          • 2. Re: bijection for entity beans
            tom_goring

             

            "gavin.king@jboss.com" wrote:
            Yes, this is by design, the domain model should not be dependent upon application logic, because the domain model is shared and changes much less often.

            Also, entity beans are often instantiated by the application instead of by Seam, and Seam can not then intercept them.


            Hi All,

            What would be the best way then to ensure all domain objects when updated get the user id of the user in the session. BiInjection seems a good way to me.

            Thanks in advance.



            • 3. Re: bijection for entity beans
              rdewell

              Tom, maybe you could try something like:

              @PreUpdate
              public void updateMyUserId(){
              MySessionBeanInterface b = Component.getInstance(MySessionBean.class, true);
              this.setUserId(b.getCurrentUserId());
              }

              The "Component" class is a Seam class: org.jboss.seam.Component. Basically, you're mainly performing the "injection" / object lookup programmatically.

              Ryan

              • 4. Re: bijection for entity beans
                gavin.king

                IMO, the best way is to do all that kind of thing from that action listener method.