我在Java 6 上运行的websphere 8.5.5.4上使用Hibernate 4.2.21
数据库:Microsoft SQL Server 2012
有时,当我尝试使用以下代码更新实体时:
this.transaction.begin();
// lots of lines of code here before the merge
merge(carentrypermitrequest);
this.transaction.commit(); // exception here
这就是我获得会话工厂的方式:
protected SessionFactory getSessionFactory() {
try {
return (SessionFactory) new InitialContext().lookup("SessionFactory");
} catch (Exception e) {
log.error("Could not locate SessionFactory in JNDI", e);
throw new IllegalStateException("Could not locate SessionFactory in JNDI");
}
}
这就是我获得交易的方式:
public final UserTransaction transaction = getUserTransaction();
protected UserTransaction getUserTransaction() {
try {
return (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
} catch (NamingException e) {
e.printStackTrace();
System.err.println("Could not locate UserTransaction in JNDI" + e.getMessage());
throw new IllegalStateException("Could not locate UserTransaction in JNDI");
}
}
这是合并方法:
public CarEntryPermitRequest merge(CarEntryPermitRequest detachedInstance) {
try {
CarEntryPermitRequest result = (CarEntryPermitRequest) sessionFactory.getCurrentSession()
.merge(detachedInstance);
return result;
} catch (RuntimeException re) {
throw re;
}
}
慕森王
吃鸡游戏
相关分类