Hello,
My application is running perfectly fine with tomcat. When I deploy it on
JBOSS server, I get unknown entity exception. I have invested lot of time in resolving this and couldn't resolve it.
Please help....
Query Model
-------------
Code:
import org.hibernate.annotations.GenericGenerator;
import java.io.Serializable;
import java.util.Calendar;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@Table(name = "query")
public class Query implements Serializable{
private String queryId;
private String queryRefId;
private String primaryKey;
private Calendar receivedDate;
private Calendar startdate;
private Calendar enddate;
private String callbackURL;
private Calendar completionDate;
private Integer status;
private String executionLog;
private String queryKeyInfo;
private Set<QueryResult> queryResults = new HashSet<QueryResult>();
@Id
@Column(name = "query_id")
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
public String getQueryId() {
return queryId;
}
public void setQueryId(String queryId) {
this.queryId = queryId;
}
@Column(name = "query_ref_id")
public String getQueryRefId() {
return queryRefId;
}
public void setQueryRefId(String queryRefId) {
this.queryRefId = queryRefId;
}
@Column(name = "primary_key")
public String getPrimaryKey() {
return primaryKey;
}
public void setPrimaryKey(String primaryKey) {
this.primaryKey = primaryKey;
}
@Column(name = "received_date")
public Calendar getReceivedDate() {
return receivedDate;
}
public void setReceivedDate(Calendar receivedDate) {
this.receivedDate = receivedDate;
}
@Column(name = "start_date")
public Calendar getStartdate() {
return startdate;
}
public void setStartdate(Calendar startdate) {
this.startdate = startdate;
}
@Column(name = "end_date")
public Calendar getEnddate() {
return enddate;
}
public void setEnddate(Calendar enddate) {
this.enddate = enddate;
}
@Column(name = "callback_url")
public String getCallbackURL() {
return callbackURL;
}
public void setCallbackURL(String callbackURL) {
this.callbackURL = callbackURL;
}
@Column(name = "completion_date")
public Calendar getCompletionDate() {
return completionDate;
}
public void setCompletionDate(Calendar completionDate) {
this.completionDate = completionDate;
}
@Column(name = "status")
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
@Column(name = "exec_log")
public String getExecutionLog() {
return executionLog;
}
public void setExecutionLog(String executionLog) {
this.executionLog = executionLog;
}
@Column(name = "key_info")
public String getQueryKeyInfo() {
return queryKeyInfo;
}
public void setQueryKeyInfo(String queryKeyInfo) {
this.queryKeyInfo = queryKeyInfo;
}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "query")
@JoinColumn(name = "query_id", nullable = false)
public Set<QueryResult> getQueryResults() {
return queryResults;
}
public void setQueryResults(Set<QueryResult> queryResults) {
this.queryResults = queryResults;
}
}
QueryResult Model
-------------
Code:
import org.hibernate.annotations.GenericGenerator;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.sql.Blob;
import java.sql.SQLException;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
@Entity
@Table(name = "query_result")
public class QueryResult implements Serializable{
private static final long serialVersionUID = 3791908272200432997L;
private String queryResultId;
private Query query;
private String resultSource;
private byte[] data;
private int responseCode;
private String responseMessage;
@Id
@Column(name = "query_result_id")
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
public String getQueryResultId() {
return queryResultId;
}
public void setQueryResultId(String queryResultId) {
this.queryResultId = queryResultId;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "query_id", nullable = false)
public Query getQuery() {
return query;
}
public void setQuery(Query query) {
this.query = query;
}
@Column(name = "source")
public String getResultSource() {
return resultSource;
}
public void setResultSource(String resultSource) {
this.resultSource = resultSource;
}
@Column(name = "data")
@Lob
public byte[] getData() {
return data;
}
public void setData(byte[] data) {
this.data = data;
}
@Transient
public int getResponseCode() {
return responseCode;
}
public void setResponseCode(int responseCode) {
this.responseCode = responseCode;
}
@Transient
public String getResponseMessage() {
return responseMessage;
}
public void setResponseMessage(String responseMessage) {
this.responseMessage = responseMessage;
}
// public Blob getDataBlob() {
// return Hibernate.createBlob(this.data);
// }
public byte[] toByteArray(Blob fromBlob) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
return toByteArrayImpl(fromBlob, baos);
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (baos != null) {
try {
baos.close();
} catch (IOException ex) {
}
}
}
}
private byte[] toByteArrayImpl(Blob fromBlob, ByteArrayOutputStream baos)
throws SQLException, IOException {
byte[] buf = new byte[4000];
InputStream is = fromBlob.getBinaryStream();
try {
for (;;) {
int dataSize = is.read(buf);
if (dataSize == -1) {
break;
}
baos.write(buf, 0, dataSize);
}
} finally {
if (is != null) {
try {
is.close();
} catch (IOException ex) {
}
}
}
return baos.toByteArray();
}
}
hibernate.cfg.xml (This is in WEB-INF/classes folder)
-----------------
Code:
<hibernate-configuration>
<session-factory>
<mapping class="com.example.model.Query"/>
<mapping class="com.example.model.QueryResult"/>
</session-factory>
</hibernate-configuration>
Stack Trace
------------
2011-07-27 12:50:24,375 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/DQM-0.0.1-SNAPSHOT].[QueryServlet]] (http-127.0.0.1-9191-1) Servlet.service() for servlet QueryServlet threw exception: org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: com.example.model.Query; nested exception is org.hibernate.MappingException: Unknown entity: com.example.model.Query
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:679) [:3.0.5.RELEASE]
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412) [:3.0.5.RELEASE]
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411) [:3.0.5.RELEASE]
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) [:3.0.5.RELEASE]
at org.springframework.orm.hibernate3.HibernateTemplate.merge(HibernateTemplate.java:813) [:3.0.5.RELEASE]
at com.example.dao.GenericDaoHibernate.save(GenericDaoHibernate.java:121) [:]
at com.example.service.QueryManagerImpl.makeRequest(QueryManagerImpl.java:97) [:]
at com.example.service.QueryManagerImpl.requestDQAs(QueryManagerImpl.java:52) [:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_26]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_26]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_26]
at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_26]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309) [:3.0.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) [:3.0.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) [:3.0.5.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) [:3.0.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [:3.0.5.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) [:3.0.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [:3.0.5.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) [:3.0.5.RELEASE]
at $Proxy143.requestDQAs(Unknown Source) at com.example.servlet.QueryServlet.doPost(QueryServlet.java:61) [:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) [:3.0.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) [:3.0.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.0.0.Final]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [:6.0.0.Final]
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.0.0.Final]
at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.0.0.Final]
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.0.0.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [:6.0.0.Final]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.0.0.Final]
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.0.0.Final]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.0.0.Final]
at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.0.0.Final]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.0.0.Final]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.0.0.Final]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.0.0.Final]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.0.0.Final]
at java.lang.Thread.run(Thread.java:662) [:1.6.0_26]
Caused by: org.hibernate.MappingException: Unknown entity: com.example.model.Query
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:691) [:3.6.0.Final]
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1485) [:3.6.0.Final]
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:232) [:3.6.0.Final]
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:84) [:3.6.0.Final]
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:867) [:3.6.0.Final]
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:851) [:3.6.0.Final]
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:855) [:3.6.0.Final]
at org.springframework.orm.hibernate3.HibernateTemplate$23.doInHibernate(HibernateTemplate.java:817) [:3.0.5.RELEASE]
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406) [:3.0.5.RELEASE]
... 44 more