我是一个 Hibernate 新手,将一个模块从遗留的Java-Hibernate项目中分离出来。抛出异常时,一些Unknown entity:
消息也会打印到错误日志中。从其他相关的questions,我看到它可以修复。但是,我很好奇Unknown entity
实际上是什么意思。
试图说出的错误日志是什么? 它只是告诉我涉及的实体类是什么? 如果我将配置修复为包含实体类,我的错误日志会如何变化?
我无法重现错误,所以当再次发生相同的异常时,我无法看到配置更改如何影响错误日志。
在此处查看示例异常:
[2015 Feb 02 00:15:19.836] [Camel (camel) thread #0 - seda://exceptions] ERROR (TradeDAO.java:75) - Unknown entity: myProject.data.util.TradeExceptionObject
[2015 Feb 02 00:15:19.857] [Camel (camel) thread #0 - seda://exceptions] ERROR (TradeExceptionHandler.java:83) - Unknown entity: myProject.data.util.TradeExceptionObject
hib.hbm.xml
<hibernate-mapping>
<class name="myProject.data.Trade" table="TRADE" optimistic-lock="version">
</hibernate-mapping>
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
public class TradeExceptionHandler implements Processor {
private TradeDAO tradeDao;
@Override
public void process(Exchange exchange) throws Exception {
// ... code here
try {
tradeDao.saveOrUpdate(excptObj);
/* LINE 83 */ } catch(Exception ignore) {LOG.error(ignore.getMessage());}
// ... code here
}
public void setTradeDao(TradeDAO tradeDao) {
}
public TradeDAO getTradeDao() {
}
}
TradeDAO.java
package myProject.persistence;
import org.hibernate.*;
public class TradeDAO implements DisposableBean {
public TradeDAO() {
}
public <E> void saveOrUpdate(E obj) throws Exception {
saveOrUpdate(obj,0);
}
private <E> void saveOrUpdate(E obj,int attempt) throws Exception {
Transaction tx = null;
Session session = sessionFactory.getCurrentSession();
try {
if(obj != null) {
tx = session.beginTransaction();
add(obj, session);
session.getTransaction().commit();
}
}
catch (Exception ex) {
LOG.error(ex.getMessage());
throw ex;
}
}
/* Make a query to database using hibernate */
@SuppressWarnings("unchecked")
public <E> List<E> get(final Class<E> clz,
Map<? extends String, Object> eqCond){
}
private <E> void add(E obj, Session session) {
session.saveOrUpdate(obj);
session.flush();
}
}