DAO实例不在服务类中工作 - NullPointerException

时间:2018-04-02 00:14:12

标签: spring jpa spring-data-jpa dao autowired

在我的spring启动项目中,我在我的数据库中创建了一个Repository接口(扩展了CRUDRepository)和Table的Entity类。

这是我的回购:

@Repository
public interface AuthPaymentDao extends CrudRepository<TFraudCard,String>   {

    @Query("SELECT t FROM TFraudCard t where t.tokenNumber = (?1)")
    TFraudCard findByTokenNumber(String tokenNumber);

}

这是我的实体类(TOKEN_NUMBER是TFRAUDCARD表中的主键):

@Entity
@Table(name = "TFRAUDCARD")
public class TFraudCard {

    @Id
    @Column(name="TOKEN_NUMBER")
    private String tokenNumber;

    @Column(name="TRANSACTIONNUMBER")
    private int transactionNumber;

    @Column(name="CARDNUMBER")
    private int cardNumber;

    @Column(name="DATEADDED", insertable = false, updatable = false, nullable = false)
    private Timestamp dateAdded;

    @Column(name="CALLINGENTITY", nullable = false)
    private String callingEntity;

    @Column(name="ACCOUNTID")
    private String accountId;

    @Column(name="ROUTINGNUMBER")
    private String routingNumber;

    @Column(name="BANKACCOUNTNUMBER")
    private String bankAccountNumber;

    @Column(name="COMMENTS")
    private String comments;

    @Column(name="USERID")
    private String userId;

    @Column(name="REMOVEDATE")
    private Timestamp removeDate;

    public String getTokenNumber() {
        return tokenNumber;
    }

    public void setTokenNumber(String tokenNumber) {
        this.tokenNumber = tokenNumber;
    }

    public int getTransactionNumber() {
        return transactionNumber;
    }

    public void setTransactionNumber(int transactionNumber) {
        this.transactionNumber = transactionNumber;
    }

    public int getCardNumber() {
        return cardNumber;
    }

    public void setCardNumber(int cardNumber) {
        this.cardNumber = cardNumber;
    }

    public Timestamp getDateAdded() {
        return dateAdded;
    }

    public void setDateAdded(Timestamp dateAdded) {
        this.dateAdded = dateAdded;
    }

    public String getCallingEntity() {
        return callingEntity;
    }

    public void setCallingEntity(String callingEntity) {
        this.callingEntity = callingEntity;
    }

    public String getAccountId() {
        return accountId;
    }

    public void setAccountId(String accountId) {
        this.accountId = accountId;
    }

    public String getRoutingNumber() {
        return routingNumber;
    }

    public void setRoutingNumber(String routingNumber) {
        this.routingNumber = routingNumber;
    }

    public String getBankAccountNumber() {
        return bankAccountNumber;
    }

    public void setBankAccountNumber(String bankAccountNumber) {
        this.bankAccountNumber = bankAccountNumber;
    }

    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public Timestamp getRemoveDate() {
        return removeDate;
    }

    public void setRemoveDate(Timestamp removeDate) {
        this.removeDate = removeDate;
    }

    public TFraudCard() {
        super();
    }

    public TFraudCard(String tokenNumber, int transactionNumber, int cardNumber, Timestamp dateAdded,
            String callingEntity, String accountId, String routingNumber, String bankAccountNumber, String comments,
            String userId, Timestamp removeDate) {
        super();
        this.tokenNumber = tokenNumber;
        this.transactionNumber = transactionNumber;
        this.cardNumber = cardNumber;
        this.dateAdded = dateAdded;
        this.callingEntity = callingEntity;
        this.accountId = accountId;
        this.routingNumber = routingNumber;
        this.bankAccountNumber = bankAccountNumber;
        this.comments = comments;
        this.userId = userId;
        this.removeDate = removeDate;
    }

    @Override
    public String toString() {
        return "TFraudCard [tokenNumber=" + tokenNumber + ", transactionNumber=" + transactionNumber + ", cardNumber="
                + cardNumber + ", dateAdded=" + dateAdded + ", callingEntity=" + callingEntity + ", accountId="
                + accountId + ", routingNumber=" + routingNumber + ", bankAccountNumber=" + bankAccountNumber
                + ", comments=" + comments + ", userId=" + userId + ", removeDate=" + removeDate + "]";
    }

}

我的服务类:

enter image description here

在我的服务类中自动装配DAO实例:

enter image description here

在服务类的Method中实现DAO实例:

private void fraudCheck(PaymentDetail paymentDetail) throws RegularPaymentBusinessException {

        logger.info("INSIDE FRAUD CHECK METHOD");

        String pmtInd=paymentDetail.getPmtInd();
        logger.info("pmtInd: " + pmtInd);
        String tokenizedCardNum=paymentDetail.getTokenizedCardNum();
        logger.info("tokenizedCardNum: " + tokenizedCardNum);

        if(pmtInd.equalsIgnoreCase(VepsConstants.GIFT_CARD_IDENTIFIER) || pmtInd.equalsIgnoreCase(VepsConstants.CREDIT_CARD_IDENTIFIER) || pmtInd.equalsIgnoreCase(VepsConstants.DEBIT_CARD_IDENTIFIER)) {
            logger.info("INSIDE CARD CHECK");
            TFraudCard fraudCard = authPaymentDao.findByTokenNumber(tokenizedCardNum);
            logger.info("fraudCard Details: " + fraudCard.toString());
            if(fraudCard!=null) {
                logger.info("INSIDE EXCEPTION FLOW FOR CARD FRAUD CHECK");
                throw new RegularPaymentBusinessException(VepsConstants._9966, VepsConstants._9966_MESSAGE, VepsConstants.FAILURE);
            }
        }
}

即使我在我的方法中传递了相同的令牌号(tokenizedCardNumber)作为我TFRAUDCARD表的TOKEN_NUMBER列中的数据,但当我尝试打印时仍然会得到NullPointerException实体对象的toString()

这是我的cloudFoundry日志上的NullPointerException(单击它以查看缩放图像):

enter image description here

我在我的开发属性文件中提供了数据库详细信息:

enter image description here

我已经完成了我头脑中的每一个场景,为什么它会中断,但我仍然无法得出答案。我正在使用标有@Id的变量,即存储库中find()方法的主键。

我还添加了@Query注释,以便更加具体。

它仍然不起作用。

0 个答案:

没有答案