将jdbc查询转换为JPA本机查询

时间:2018-08-03 16:46:30

标签: jpa spring-data-jpa

下面是使用jdbc编写的代码,现在我只想将其转换为JPA的本机查询,请让我 知道我如何将使用jdbc的以下方法代码更改为本地查询等价,任何帮助将不胜感激, 这种方法只是将数据插入数据库中,我已经初始化了JPA的实体管理器

public void insertATMLog(ATMLogRow ATMlLogRow)
    conn = getConnection();
           String sQuery = "insert into CTL_LOG " +
                            "( " +
                              " CTL_LOG_ID, " +
                              " HOME_ID, " +
                              " PERSON_ID, " +
                              " FROM_ADDRESS, " +
                              " TO_ADDRESS, " +
                              " SUBJECT, " +
                              " BODY, " +
                              " STATUS, " +
                              " SENT_DATE, " +
                              " CC_ADDRESS, " +
                              " BCC_ADDRESS, " +
                              " REPLY_TO, " +
                              " CUSTOMER_INSTITUTION_ID, " +
                              " EFT_TRANSACTION_ID " +
                              " , PARTNER_EMAIL_ADDRESS , CREATED_ON , FROM_ADDRESS_ALIAS, DELIVERY_CHANNEL" +
                              ")" +
                              " values (CTL_LOG_seq.nextval,?,?,?,?,?,?,?,sysdate,?,?,?,?,?,?,systimestamp,?,?)";
           pstmt = conn.prepareStatement(sQuery);

           pstmt.setInt(1,ATMlLogRow.homeID);
           pstmt.setInt(2,ATMlLogRow.personID);
           pstmt.setString(3,ATMlLogRow.fromAddress);
           pstmt.setString(4,ATMlLogRow.toAddress);
           pstmt.setString(5,ATMlLogRow.subject);
            PCUtils.setClobColumn(pstmt,6,ATMlLogRow.body);
             pstmt.setInt(7, status);
             pstmt.setString(8,ATMlLogRow.ccAddress);
           pstmt.setString(9,ATMlLogRow.bccAddress);
           pstmt.setString(10,ATMlLogRow.replyTo);
           if (ATMlLogRow.cfiID > 2)
                pstmt.setInt(11, ATMlLogRow.cfiID);
           else
                pstmt.setNull(11, Types.INTEGER);
           if (ATMlLogRow.eftTransactionID > 3)
                pstmt.setInt(12, ATMlLogRow.eftTransactionID);
           else
                pstmt.setNull(12, Types.INTEGER);
              pstmt.setString(13, ATMlLogRow.partnerEmailAddress);
                   pstmt.setString(14, ATMlLogRow.fromAddressEmailAlias);
           pstmt.setString(15, ATMlLogRow.deliveryChannel);
                       int count = pstmt.executeUpdate();

1 个答案:

答案 0 :(得分:0)

好像您在要求什么是JPA的基本知识。

首先,您需要创建一个带有@Entity注释的POJO类。

然后,您只需根据逻辑设置字段即可。

最后只需拨打entityManager.persist