-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problems working with HAR
PostPosted: Sat Sep 13, 2008 10:54 am 
Newbie

Joined: Sat Sep 13, 2008 6:15 am
Posts: 2
Hi all,

I am working with Hibernate. And I am trying to develop an EAR that is using Hibernate inside an HAR.
This are the versions I am using:
- JBoss 4.2.2
- Hibernate 3 shipped with JBoss
- Java 6

But during the accessing of the DAO object the exception "Unknown entity" is thrown.


Inside the HAR are the following classes:

EntityUser:
Code:
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:
Code:
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:
Code:
<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>



And this is the exception that is thrown while calling the store method:
Code:
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)



This is is the way how I called the store method of the DAO object:
Code:
        EntityUser myUser = new EntityUser();
        myUser.setLoginName("loginName");
        myUser.setLoginPassword("loginPassword");

        DAOUser dao = new DAOUser();
        try {
            dao.storeUser(myUser);
        } catch (Exception e) {
            e.printStackTrace();
        }



It would be really nice if someone could help me to resolve this problem.

Greetings,
Hal


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.