2 Replies Latest reply on Jan 8, 2010 3:00 PM by Gaurav Saini

    Seam Hibernate with Xml Mappings Instead Of Hibernate Annotations

    Gaurav Saini Newbie

      I'm using hibernate with seam. For that i have used plain seam annotated DTO's which are further mapped in hibernate mapping xml files with database tables.
      The problem I'm facing is, while saving the DTO in database using save() method of hibernate API following exception is thrown:

      caused by: javax.faces.el.EvaluationException: org.hibernate.MappingException: Unknown entity: org.a3s.adp.casedetails.domain.CaseDetailsDTO$$javassistseam11
           at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
           at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
           ... 52 more
      Caused by: org.hibernate.MappingException: Unknown entity: org.a3s.adp.casedetails.domain.CaseDetailsDTO$$javassistseam11

      I have debugged the code and found that the DTO injected by seam in my DAO is actually a javaassist proxy with new name different from the one specified in my hibernate mapping file.

      Please let me know how can I fix this problem. Or is it mandatory to use hibernate annotations with seam?

        • 1. Re: Seam Hibernate with Xml Mappings Instead Of Hibernate Annotations
          Stuart Douglas Master

          I assume you have annotated you persistent class with an @Name annotation right?
          This causes seam to treat it like a normal component and generate a proxy for it so it can use interceptors etc.

          You have two options:

          1) remove the @Name annotation. This annotation does not really make sense on an entity in anyway, if you need to inject it use a factory method instead.

          2) stick an @Entity annotation on the bean and disable the hibernate auto-discovery of annotated beans. This way seam will still realise it is an entity.

          • 2. Re: Seam Hibernate with Xml Mappings Instead Of Hibernate Annotations
            Gaurav Saini Newbie

            Thanks Stuart, I have used first option and my issue gets resolved.

            I'm using spring with seam, spring is responsible for creating session factory and loading hibernate mappings. For spring-seam integration i have referred online available chapter from Seam In Action.

            I have tried second option but didn't succeed. Even after using @Entity annotation, from Hiberanate API (org.hibernate.annotations.Entity) instead of from JPA (javax.persistence.Entity), the DTO passed in DAO layer is java assist proxy.

            Actually i'm not using JPA so i haven't configured persistence.xml, hence i haven't disabled the hibernate auto-discovery of annotated beans.

            Please let me know is it the right way to use the second option?