4 Replies Latest reply on Feb 5, 2007 12:06 PM by norman.richards

    Pure JPA Persistense Layer

    afontes

      Hello,

      I'm starting the development of an application that at this point will have a single web interface but later it will be necessary to build another interfaces as well, for example a Swing front end.

      So I would like to have a pure JPA layer that doesn't import anything but javax.persistence.* classes and annotations allowing me to use it outside a jee 5 container but I also would like to use Seam and Hibernate validation in my Web Interface as I am using in other projects. Is there any way to achieve that?

      I thought about extending my pure JPA classes and then add the complementary annotations (such as @Name and @Length), but that would cause a ClassCastException later, right? My EntityManager won't persist my new classes.

      What you guys recommend me?

      Thank you in advance,
      Augusto Fontes

        • 1. Re: Pure JPA Persistense Layer
          afontes

          What a terrible misspelled subject. Can' edit post... :(

          • 2. Re: Pure JPA Persistense Layer

            You can do all the Seam configuration in XML, but I don't know of any way to express the hibernate validation annotations outside of the class. (I don't know that it isn't possible either)

            Just a side note - the annotations do not need to be present at runtime to use your class. If you declare @Length and it isn't available at runtime, your class will simply not have that metadata.

            • 3. Re: Pure JPA Persistense Layer
              afontes

              Thank you, Norman!

              Which XML can I use to define seam configuration? components.xml? Is there any example that shows this?

              Augusto

              • 4. Re: Pure JPA Persistense Layer

                Yes. components.xml can be used to declare components that don't have an @Name annotation.

                Oh, I did think of one other option, though I like it even less. You could also use JBoss AOP to add the annotations to the classes at runtime. We don't have an example of that, but the AOP guys do have examples of weaving annotations into classes.