Hey Christian,
I've read them again, but I still have the feeling they don't describe what I mean. In the 2 pages I never see a service layer that is not Hibernate aware, all the transaction code that is described in those 2 pages are hibernate wrappers around either JTA or JDBC, right? I just want to make sure that if I needed to switch back to JDBC (so no hibernate reference in the whole project, not single library), I'll be able to reuse all of my interfaces without altering them, only altering the implementation of my DAO layer.
I wanted a further extraction layer dependent on nothing but my own objects, the implementation of this layer on the other hand is off course hibernate aware.
Im pretty sure with this interface
Code:
public interface ITransaction {
public boolean begin() throws DAOException;
public boolean commit() throws DAOException;
public boolean rollback() throws DAOException;
public void end() throws DAOException;
}
It will work.
So a methodn in one of my services looks like this now
Code:
public CustomerServiceImpl(ICustomerDAO customerDao,int numLoginAttempts){
this.customerDao = customerDao;
this.defaultNumLoginAttempts = numLoginAttempts;
}
public boolean saveCustomer(ICustomer customer) Throws DAOException{
ITransaction transaction = null;
boolean retVal = false;
try {
transaction = this.customerDao.getTransaction();
transaction.begin();
retVal = this.customerDao.saveCustomerAgent(transaction, agent);
if (retVal) {
transaction.commit();
} else {
transaction.rollback();
}
} catch (Exception e) {
this._logger.error("saveCustomer " + e);
try {
transaction.rollback();
} catch (Exception e2) {
this._logger.error("saveCustomer " + e2);
}
throw new DAOException(e);
} finally {
try {
transaction.end();
} catch (Exception e2) {
this._logger.error("saveCustomer " + e2);
}
}
return retVal;
}
If one of the proposed solutions one of these pages actually does this could you tell me which one? I've read them all and as far as I can see they all force you to make your service layer hibernate transaction aware.