Hibernate / JPA仅显示选择语句。跳过了更新/删除语句,并且控制台中没有错误

时间:2019-01-05 00:24:51

标签: java spring hibernate jpa db2

我们正在使用Hibernate / JPA,我们的Delete / Update调用可在独立的JAR中使用。但是,在WAR中,仅显示SELECT语句,并且Delete / Update查询被完全跳过。他们无处可见。控制台中也没有错误,我们得到了返回的ID。

我们已经在服务层中添加了@Transactional,在存储库中也添加了@Modifying。

有人遇到过这样的事情吗?

编辑:这与我们的记录器或ProfileLogger无关。这是一个问题,即使DELETE / UPDATE语句甚至不在我们的WAR中由hibernate / jpa触发,但在我们的独立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;
}

控制器

@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;
    }

控制台

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);


}

0 个答案:

没有答案