我有一个代码,它给了我一个LazyInitialization Exception。我已按需处理它,即仅在抛出异常并采取必要的操作时才执行catch块。但是,即使我已经处理了异常,一旦控件进入catch块,在控制台上就不会出现异常的堆栈跟踪。 (因为如果处理的任何java异常都不会打印在日志文件中。)下面是我的try catch块:
try{
if (tempUser != null) {
List<FieldAreas> fieldAreasList = tempUser.getFieldAreasList();
for (FieldAreas fieldArea : fieldAreasList) {
fieldArea.getId();
break;
}
}
} catch(LazyInitializationException exception) {
//This catch block is written to handle lazy initialization exception
fetchDetailsForMerchant(merchant,defaultPricingInput);
tempUser = User.findByPrimaryKey(tempUser.getId());
List<FieldAreas> fieldAreasList = tempUser.getFieldAreasList();
for (FieldAreas fieldArea : fieldAreasList) {
fieldArea.getId();
break;
}
}