我不是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事务变更是否仅为数据库事务设计?