-->
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: Zugriff auf Klassen eines HAR wirft eine MappingException
PostPosted: Sat Sep 13, 2008 6:57 am 
Newbie

Joined: Sat Sep 13, 2008 6:15 am
Posts: 2
Hallo zusammen,

ich versuche mit in Hibernate einzuarbeiten, dabei will ich eine Application entwickeln, die auf einen JBoss deployed wird und ein HAR verwendet.
Dabei verwende ich folgende Versionen:
- JBoss 4.2.2
- Hibernate 3 die Jars aus dem JBoss
- Java 6

In meinem HAR sind folgende Klassen:

- 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>



Allerdings wird beim Versuch ein Objekt über das DAO abzuspeichern folgende Exception geworfen:
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)



Und so versuche ich das DAO-Objekt zu verwenden:
Code:
        EntityUser myUser = new EntityUser();
        myUser.setLoginName("loginName");
        myUser.setLoginPassword("loginPassword");

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



Es wäre wirklich nett wenn mir jmd helfen könnte. Ich suche schon seit ein paar Tagen im Internet nach einer Lösung konnte aber bisher noch keine finden.

Viele Grüße,
Sebastian


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.