I am not an ejb expert. I have a service class like below. I am saving a file in some location in my service class and calling a method in dao to save the file hash code. Due to some reasons some time I get an exception in my dao layer. Recently I observed the file which is saved from my service layer is not deleted when I get excxeptions.
@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;
}
}
Below id my DAO
public class UpgradePackageDaoImpl implements UpgradePackageDao {
@Override
public void savePackageHash(String hash) {
throw new RuntimeException("cannot save");
}
}
Then I annotated my service class with @TransactionManagement. What am I missing? Or am I misunderstanding ejb transaction management? Is ejb transaction mamangement designed only for database transactions?