0 Replies Latest reply on Sep 15, 2008 10:40 AM by hal arres

    Annotations inside the HAR

    hal arres Newbie

      Hi all,

      I am trying to build a jboss application that uses a hibernate archive (HAR).
      But when I am trying to access the DAO inside the HAR I got the exception "Unknown entity".

      I build the Entity using Annotations.
      Do you know if it is possible to build an HAR with Hibernate-Annotations?

      I also read that there should be a jboss-hibernate.deployer directory inside the jboss, but I can't find this directory inside my jboss. So I am a little bit confused. Do you know what I should do here?

      I am using the following versions:
      - JBoss 4.2.2
      - Hibernate 3 shipped with JBoss
      - Java 6

      My HAR contains these files:
      - EntityUser.java
      - DAOUser.java
      - hibernate-service.xml

      EntityUser:

      package de.backend.persistence.entity;
      
      import javax.persistence.Entity;
      import javax.persistence.Table;
      import javax.persistence.Id;
      import javax.persistence.Column;
      import java.io.Serializable;
      
      @Entity
      @Table(name="user")
      public class EntityUser
       implements Serializable {
      
       @Id
       @Column(name="id")
       private Long id;
      
       @Column(name="login_name")
       private String loginName;
      
       @Column(name="login_pass")
       private String loginPassword;
      
      
       public Long getId() {
       return id;
       }
      
       public void setId(Long id) {
       this.id = id;
       }
      
       public String getLoginName() {
       return loginName;
       }
      
       public void setLoginName(String loginName) {
       this.loginName = loginName;
       }
      
       public String getLoginPassword() {
       return loginPassword;
       }
      
       public void setLoginPassword(String loginPassword) {
       this.loginPassword = loginPassword;
       }
      
      }
      


      DAOUser:
      package de.backend.persistence.dao;
      
      import org.hibernate.SessionFactory;
      import org.hibernate.Session;
      
      import javax.naming.InitialContext;
      
      import de.backend.persistence.entity.EntityUser;
      
      
      public class DAOUser {
      
       public void storeUser(EntityUser user)
       throws Exception {
       InitialContext ctx = new InitialContext();
       SessionFactory factory = (SessionFactory)ctx.lookup("java:/hibernate/SessionFactoryBase");
       Session hsession = factory.openSession();
       hsession.beginTransaction();
       hsession.save(user);
       hsession.getTransaction().commit();
       }
      
      }
      


      hibernate-service.xml:
      <server>
       <mbean code="org.jboss.hibernate.jmx.Hibernate" name="jboss.har:service=Hibernate">
       <attribute name="DatasourceName">java:/base</attribute>
       <attribute name="Dialect">org.hibernate.dialect.PostgreSQLDialect</attribute>
       <attribute name="DefaultSchema">public</attribute>
       <attribute name="SessionFactoryName">java:/hibernate/SessionFactoryBase</attribute>
       <attribute name="CacheProviderClass">org.hibernate.cache.HashtableCacheProvider</attribute>
       <!--<attribute name="Hbm2ddlAuto">create-drop</attribute>-->
       <attribute name="ShowSqlEnabled">true</attribute>
       </mbean>
      </server>
      



      This is the Exception that I get when I am trying to access the DAO:
      11:19:11,437 ERROR [STDERR] org.hibernate.MappingException: Unknown entity: de.backend.persistence.entity.EntityUser
       at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:550)
       at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1338)
       at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:98)
       at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
       at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
       at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
       at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
       at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
       at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
       at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
       at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
       at de.backend.persistence.dao.DAOUser.storeUser(DAOUser.java:23)
       at de.backend.crs.bean.calculator.CalculatorBean.storeMyUser(CalculatorBean.java:52)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
       at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
      




      It would be realy nice if you could tell me if I forgot some configuration or make some mistake in developing.
      I am getting despreate because I don't know what I can do anymore.

      I am looking forward for any help.
      Thanks in advance,
      Hal