Hello all,
I have a transactional method in my service tier marked using the @transactional annotation:
What I want the method to do is to persist the entity into the database *only if* the entity is valid according to some business rules. However, the actual behavior of the method is that, somehow, the entity is being persisted via the DAO even if isEntityValid returns false. I ran the debugger and, for invalid entities, the code did not actually execute the call to entityDAO.save(). However, the query to save the entity is executed looking at the log file, and since the entity is not valid, the application threw some Oracle database exception.Code:@Transactional(readOnly=false) public void saveEntity(Entity entity) { if (isEntityValid(entity)) { entityDAO.save(entity); } else { doSomethingElse(); } } private boolean isEntityValid(Entity entity) { // validate the entity and return true or false }
My question is, why would the the query to save the entity get executed if isEntityValid() returns false? I suspect this has to do with the method being marked as transactional. Also, what do I need to modify such that, if the entity is invalid, the query to save it will not get executed?
Thanks for any help in advance.


Reply With Quote
.