[jboss-user] Problems in working with a Hibernate-Archive
hal arres
forum.arres at gmx.de
Mon Sep 15 13:22:20 EDT 2008
Hi all,
I am new to Jboss and 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".
Now, after I searched in many threads for a solution I hope I can find some help in here.
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:
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>
This is the Exception that I get when I am trying to access the DAO from a SessionBean:
Code:
11:19:11,437 ERROR [STDERR] org.hibernate.MappingException: Unknown entity: de.backend.persistence.e
ntity.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(AbstractSaveEventListene
r.java:98)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(Defaul
tSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEve
ntListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdate
EventListener.java:172)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.
java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEve
ntListener.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 really nice if you could tell me if I forgot some configuration or make some mistake in developing.
I am looking forward for any help.
Thanks in advance,
Arres
--
GMX Kostenlose Spiele: Einfach online spielen und Spaß haben mit Pastry Passion!
http://games.entertainment.gmx.net/de/entertainment/games/free/puzzle/6169196
More information about the jboss-user
mailing list