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