Мы используем Hibernate / JPA, и наши вызовы Delete / Update работают в автономном JAR. Однако в WAR отображаются только операторы SELECT, а запросы на удаление / обновление полностью пропускаются. Их нигде не видно. В консоли также нет ошибок, и мы получаем возвращенный идентификатор.
Мы добавили @Transactional в наш сервисный слой и @Modifying в наш репозиторий.
Кто-нибудь сталкивался с чем-то подобным?
РЕДАКТИРОВАТЬ: Это не проблема нашего регистратора или ProfileLogger. Это проблема, когда операторы DELETE / UPDATE даже не запускаются hibernate / jpa в нашей WAR, а работают в нашем автономном jar. Может ли это иметь какое-либо отношение к нашим транзакциям?
DAO
@Repository
@PersistenceContext(unitName = "dbObjEntityManagerFactory")
public class DeleteDbObjDaoImpl implements DeleteDbObjDao {
private static final String LOGGING_CLASS =
"DeleteDataObjDetailsDaoImpl";
@Autowired
private ProfileLogger logger;
@Autowired
Repo1 repo1;
@Autowired
Repo2 repo2;
@Autowired
Repo3 repo3;
@Autowired
Repo4 repo4;
@Override
public DbObjInfo deleteDbObjDetails(String id1, String id2, String id3,
String id4){
String LOGGING_METHOD = "deleteItemFromDb";
logger.writeToTraceLog(sessionId, DeleteItemConstant.ENTRY+" For USERID
"+userId, LoggerLevel.INFO, LOGGING_CLASS,
LOGGING_METHOD, null);
DbOjbInfo dbObjInfo = getDbObjDao.getDbObjDetails(id1, id2, id3, id4);
try {
deleteDataObj.deleteBySourceAcctNo(id1);
}
catch(DeleteDataObjSvcDBException e){
logger.writeToTraceLog(sessionId, DeleteItemContant.EXIT+" For
USERID "+userId, LoggerLevel.INFO, LOGGING_CLASS,
LOGGING_METHOD, null);
throw new DeleteItemSvcException(e.getDescription());
}
catch(Exception e){
logger.writeToTraceLog(sessionId, "Error while deleting data for
DbOjb # " + id1 +" from database "+" For USERID "+userId+ " Error Message
is "+e.getMessage(),
LoggerLevel.ERROR, LOGGING_CLASS, LOGGING_METHOD, null);
e.printStackTrace();
logger.writeToTraceLog(sessionId, DeleteDataObj.EXIT,
LoggerLevel.INFO, LOGGING_CLASS,
LOGGING_METHOD, null);
throw new DeleteDataObjSvcDBException(DeleteDataObjConstants.DATA_OBJ_DB_DELETE_FAILED);
}
logger.writeToTraceLog(sessionId, DeleteDbDataObjConstants.EXIT+" For USERID "+userId, LoggerLevel.INFO, LOGGING_CLASS,
LOGGING_METHOD, null);
return dbObjInfo;
}
СЕРВИС
@Service
@EnableTransactionManagement
@PersistenceContext(unitName = "dbDataObjEntityManagerFactory")
public class DataObjDeleteServiceImpl implements DataObjDeleteService {
private static final String LOGGING_CLASS = "DataObjDeleteServiceImpl";
@Autowired
private ProfileLogger logger;
@Autowired
DeleteDataObjDao deleteDataObjDetailsDao;
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackForClassName = {
"Exception"})private String deleteDataObj(String id1, String id2, String id3,
String id4) {
String LOGGING_METHOD = "deleteDataObj";
logger.writeToTraceLog(sessionId, DeleteDataObjConstants.ENTRY+" For USERID "+id1, LoggerLevel.INFO, LOGGING_CLASS,
LOGGING_METHOD, null);
DataObjInfo dataObjInfo = null;
logger.writeToTraceLog(sessionId, "Deleting for dataObj # " + id,
LoggerLevel.INFO, LOGGING_CLASS, LOGGING_METHOD, null);
ResponseEntity<AccountAuditInfo> responseEntity = null;
try{
DeleteDataObj deleteDataObj =
deleteDataObjDetailsDao.deleteDbObjDetails(id1, id2, id3, id4);
}
}
catch (DeleteDataObjSvcDBException ex) {
throw new DeleteDataObjSvcSystemException(objErrorVOList);
}
logger.writeToTraceLog(id, DeleteDataObjConstants.EXIT+" For USERID "+id, LoggerLevel.INFO, LOGGING_CLASS,
LOGGING_METHOD, null);
return id;
}
CONTROLLER
@RequestMapping(path = "/associates/{dbObjId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> deleteDbObj(
@PathVariable("dbObjId") String id,
@RequestHeader(value = "Request-ID", required = false, defaultValue = "") String id2,
@RequestHeader(value = "Consumer-Id", required = false, defaultValue = "") String id3)
ResponseEntity<Object> response = null;
String LOGGING_METHOD = "deleteDbObj";
String id4 = UUID.randomUUID().toString();
response = dataObjDeleteService.deleteDataObjDetails(id, id2, id3, id4);
return response;
}
CONSOLE
15:37:26,077 INFO [org.javers.core.metamodel.scanner.ScannerModule] (http-/127.0.0.1:8179-1) using FIELD mappingStyle
15:37:26,077 INFO [org.javers.core.JaversBuilder] (http-/127.0.0.1:8179-1) loading GuavaAddOns ...
15:37:26,078 INFO [org.javers.core.JaversBuilder] (http-/127.0.0.1:8179-1) loading JodaAddOns ...
15:37:26,079 INFO [org.javers.core.JaversBuilder] (http-/127.0.0.1:8179-1) using fake InMemoryRepository, registerType actual implementation via JaversBuilder.registerJaversRepository()
15:37:26,079 INFO [org.javers.core.JaversBuilder] (http-/127.0.0.1:8179-1) JaVers instance started in 2 ms
15:37:26,080 INFO [TraceLogger] (http-/127.0.0.1:8179-1) dbff0d61-36d5-4f1b-a2d8-d2f0895cd604[DeleteDataObjDaoImpl-deleteDbObjDetails]Entry
15:37:26,081 INFO [stdout] (http-/127.0.0.1:8179-1) Hibernate: select entty1.entty1_ID as assoc1_en1_14_, t111assoc0_.assoc_name as entt2_AL2_14_, entt3.ASSOC_BIRTH_CITY_NM as ASSOC_entty3_, entty2.ASSOC_BIRTH_CTZN_CTRY_ID as assoc_entty2_BI4_14_, entty2.assoc_entty_birth as assoc_entty_10_11, entty2.assoc_entty_date as assoc_entty_ca2
15:37:26,273 INFO [TraceLogger] (http-/127.0.0.1:8179-1) dbff0d61-36d5-4f1b-a2d8-d2f0895cd604[DbDataObjServiceImpl-deleteDataObj]Exit For ID
Репозиторий JPA
@Repository
@Transactional
@PersistenceContext(unitName = "dbObjEntityManagerFactory")
public interface dbObjRepository extends JpaRepository<dbObj, Integer>{
dbObj findBySourceAcctNo(String sourceAcctNo);
/* String deleteBySourceAcctNo(String id);*/
@Modifying
@Transactional
@Query(value = "delete from dbObjEntty a where a.sourceAcctNo =?1")
void deleteBySourceAcctNo(String sourceAcctNo);
}