I have a rest class which accepts a multipart request, saves a file in a particular location and calls an ejb service to save so hash in our database.
The flow is like below
Rest -> service -> dao
In my service class I am injecting the dao. Due to some reason the dao is not initialized and injected into the service class and I get a null pointer exception.
The file should be deleted in this case because ejbs have transaction management capabilities. But the file is not being deleted. Do I need to additionally enable transaction management somewhere in the container?
My rest class is not an ejb. Is it because my rest class is not an ejb, that is why the file is not being deleted?
BTW I am using jboss eap 6.1
Can anyone please help?
For simplicity I have written a new code with almost same thing my original code is doing
@Stateless
@Local
@TransactionManagement
public class ImportUpgradeServiceImpl implements ImportUpgradeService {
@Inject
private UpgradePackageDao upgradePackageDao;
@Override
public boolean savePackage() {
File file = new File("d:\\ejbtest.log");
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
upgradePackageDao.savePackageHash(null);
return false;
}
}
Below is my DAO
public class UpgradePackageDaoImpl implements UpgradePackageDao {
@Override
public void savePackageHash(String hash) {
throw new RuntimeException("cannot save");
}
}
I ran the ejb with @TransactionManagement and without @TransactionManagement. Both scenarios I can still see "ejbtest.log" file created in my D: drive