【发布时间】:2014-03-17 04:21:29
【问题描述】:
我不是 ejb 专家。我有一个像下面这样的服务类。我在我的服务类的某个位置保存一个文件,并在 dao 中调用一个方法来保存文件哈希码。由于某些原因,有时我的 dao 层出现异常。最近我观察到当我得到异常时,从我的服务层保存的文件没有被删除。
@Stateless
@Local
@TransactionManagement
public class ImportUpgradeServiceImpl implements ImportUpgradeService {
@Inject
private UpgradePackageDao upgradePackageDao;
@Override
public boolean savePackage() {
//For the sake of simplicity I simplified the code here
File file = new File("d:\\ejbtest.log");
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
upgradePackageDao.savePackageHash(null);
return false;
}
}
下面是我的 DAO
public class UpgradePackageDaoImpl implements UpgradePackageDao {
@Override
public void savePackageHash(String hash) {
throw new RuntimeException("cannot save");
}
}
然后我用@TransactionManagement 注释了我的服务类。我错过了什么?还是我误解了ejb事务管理? ejb 事务管理是专为数据库事务设计的吗?
【问题讨论】:
-
有人能解释一下吗?
-
谁能回答我的问题?
-
看看前两个答案here
标签: java transactions ejb-3.0