0
ClientEntity clientEntity;
try {
clientEntity = entityManager.getReference(ClientEntity.class, clientId);
}
catch (EntityNotFoundException ex){
System.out.println("Wrong client id: there are no client with such id.");
return;
}
我发送了错误的参数值。在数据库中肯定没有这样的客户端(例如id = 6)。但catch {}
没有工作。休眠无法捕捉异常
从getReference
文档:
如果请求的情况下不存在于数据库中,该实例的状态是第一个当 访问 EntityNotFoundException被抛出。 (持久性提供程序运行时允许扔 EntityNotFoundException时getReference被调用。)
但在调试器,我们可以看到,EntityNotFoundException
发生。 我在做什么错?
这抓住了我的。 –