【发布时间】:2011-02-24 18:58:46
【问题描述】:
在抛出约束违反异常后,有什么方法可以继续使用线程绑定的休眠会话?我在这里举一个简短的例子:
Parent other=service.load(33); // loads a new parent
try {
Parent p=new Parent();
p.setName("A name");
service.save(p); // a @Transactional spring service class, throws ConstraintViolationException - name should be at least 15 characters long
} catch (ConstraintViolationException e){
// i would like to handle validation errors and proceed normally
// but the session is allready closed here
}
System.out.println("Children: " + other.getChildren()); // lazy initialization exception, even when using opensessioninview
从现在开始,休眠会话完全没用,即使对于只读操作,例如使用 OpenSessionInView 模式在视图中呈现惰性集合也是如此。
【问题讨论】:
标签: hibernate