3 Replies Latest reply on Aug 11, 2009 4:20 PM by Nikos Paraskevopoulos

    Question: Seam and Reusability

    Brendan Farragher Newbie

      Is it possible to package entity beans in such a way that they would be reusable across applications? My manager and I have been discussing this issue.


      If I annotate an entity bean with Seam annotations (for say, UI validation via regex), but then I want to reuse that same entity bean in a completely different application (perhaps in a backend MDB or something), I would have to pull in the Seam libraries just to get the entity bean to compile inside the new project (because of the annotations that I added to it).


      Alternatively, I could develop a wrapper bean for the entity bean and annotate the wrapper bean with the Seam validation annotations, but am I not then sort of re-creating the basic Struts action form validation by letting the wrapper bean validate for me?


      Thanks for your input.

        • 1. Re: Question: Seam and Reusability
          Stuart Douglas Master

          As far as I am aware JVM's are meant to ignore unkown annotations rather than throwing ClassNotFoundException.

          • 2. Re: Question: Seam and Reusability
            Brendan Farragher Newbie

            Thanks for replying, Stuart. The problem that still seems to exist is reusability. I would like the reusability to be present across all applications (Seam and non-Seam). If I annotate an entity bean with Seam UI validation annotations for one application, then those annotations may not be applicable to a completely different Seam application context. This forces me to duplicate the entity bean so that it can be annotated differently for a second Seam application (consider that Hibernate entity pojos can be reused and their behavior can be altered in different contexts via application-specific hibernate mapping files).


            This would lead me to believe that Seam UI validation annotations (or the functionality that they provide) belong outside of the entity bean code. The annotations in the scenario I am describing prevent the entity bean from being reusable across multiple Seam applications. It may be said that the entity bean could possibly be extended and overriden, but the inheritance approach seems a little messy IMO.

            • 3. Re: Question: Seam and Reusability
              Nikos Paraskevopoulos Novice

              Hi Brendan,


              I believe that if the validation is intrinsic to the entity, it can be modelled as a Seam/Hibernate validation annotation. If it is not, then indeed it belongs to another layer, eg rules.


              For example consider an entity representing a person. The age field should be grater than zero, and this is an intrinsic rule: it doesnt make sense for age to be less than 0. However, in a loan application, the age might have the additional constraint that it is above 18 and below 65. I believe the latter constraint belongs to the rules of the specific application, not the entity.