5 Replies Latest reply on Jun 4, 2007 10:07 AM by christian.bauer

    Is @Entity required for Seam w/ Hibernate in Java EE

    mcalello

      I was using the hibernate example to learn how to use Seam without EJB3, and was surprised to see that all of the Hibernate3 pojos use the @Entity (javax.persistence.Entity) annotation.

      Is this a mistake in the example, or I am misunderstanding something?


      Cheers,
      -Marc

        • 1. Re: Is @Entity required for Seam w/ Hibernate in Java EE
          jazir1979

          AFAIK, Hibernate Annotations uses the standard EJB3 annotations, as well as providing extras that are in the org.hibernate.* package.

          From the website:

          "The Hibernate Annotations package includes:

          * Standardized Java Persistence and EJB 3.0 (JSR 220) object/relational mapping annotations
          * Hibernate-specific extension annotations for performance optimization and special mappings"

          This is good because even though you are using Hibernate directly, it would be very easy for you to go to EJB3 later on.

          • 2. Re: Is @Entity required for Seam w/ Hibernate in Java EE
            mcalello

            So does this mean that all applications are required to use ejb3 annotations, even if they are not using EJB3??

            • 3. Re: Is @Entity required for Seam w/ Hibernate in Java EE
              christian.bauer

              It means exactly the opposite. You can use whatever you want wherever you want, it's all modular.

              • 4. Re: Is @Entity required for Seam w/ Hibernate in Java EE
                mcalello

                Thanks Christian,

                It means exactly the opposite. You can use whatever you want wherever you want, it's all modular.


                That is what I thought, but in the hibernate example, I get these errors when I remove these EJB3 annotations:
                org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [select username from User where username=:username]


                So it appears to be serving a purpose in the example, and I had thought that the mappings in the hibernate.cfg.xml:
                <mapping class="org.jboss.seam.example.hibernate.Hotel"/>
                 <mapping class="org.jboss.seam.example.hibernate.User"/>
                 <mapping class="org.jboss.seam.example.hibernate.Booking"/>


                would have served the same purpose. So is the hibernate example wrong, or is it just a little confusing?

                Thanks for the help!
                -Marc

                • 5. Re: Is @Entity required for Seam w/ Hibernate in Java EE
                  christian.bauer

                  Of course you need to provide metadata. If you don't like the ones from the javax.persistence package, use Hibernate XML metadata.