无法在具有查询注释的日期jpa数据之间执行

时间:2018-09-12 08:35:57

标签: java spring spring-boot spring-data-jpa

我正在使用org.springframework.data.jpa.repository.Query批注使用spring jpa数据填充结果集。我有一个billing history表,其中有一个列creationdate。我想通过sql注释使用date between @Query查询。下面是我的代码:

@Query( "SELECT billhistory FROM BillingHistory billhistory INNER JOIN billhistory.userInfo user WHERE user.userName = :username AND billhistory.creationdate between :from and :to" )
List<BillingHistory> getBillingHistoryByUserNameAndDate( @Param("username") String username, @Param("from")Date from, @Param("to") Date to );

在这里,我还尝试了Stringfrom参数的to数据类型。但是我的SpringBoot应用程序出现了以下错误:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'billingHistoryController' defined in file [D:\newWorkSpace\JasperReport_project\target\classes\com\google\jasper\controller\BillingHistoryController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'billingHistoryServiceImpl' defined in file [D:\newWorkSpace\JasperReport_project\target\classes\com\google\jasper\service\BillingHistoryServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'billingHistoryRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List com.google.jasper.repository.BillingHistoryRepository.getBillingHistoryByUserNameAndDate(java.lang.String,java.lang.String,java.lang.String)!

***** EDIT *****

BillingHistory实体

package com.google.jasper.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonFormat;

@Entity
@Table( name = "billing_history", catalog = "radius" )
public class BillingHistory implements Serializable{

    private static final long serialVersionUID = 8329286536383150966L;

    @Id
    @GeneratedValue( strategy = GenerationType.AUTO )
    @Column( name = "id", nullable = false, updatable = false )
    private Integer id;

    @ManyToOne()
    @JoinColumn( name = "username" )
    private UserInfo userInfo;

    @ManyToOne
    @JoinColumn( name = "planId" )
    private BillingPlans billingPlans;

    @Column( name = "billAmount" )
    private String billAmount;

    @Column( name = "billAction" )
    private String billAction;

    @Column( name = "billPerformer" )
    private String billPerformer;

    @Column( name = "billReason" )
    private String billReason;

    @Column( name = "paymentMethod" )
    private String paymentMethod;

    @Column( name = "cash" )
    private String cash;

    @Column( name = "creditcardname" )
    private String creditcardName;

    @Column( name = "creditcardnumber" )
    private String creditcardNumber;

    @Column( name = "creditcardtype" )
    private String creditcardType;

    @Column( name = "creditcardexp" )
    private String creditcardExp;

    @Column( name = "coupon" )
    private String coupon;

    @Column( name = "discount" )
    private String discount;

    @Column( name = "notes" )
    private String notes;

    @JsonFormat( pattern = "dd-MM-yyyy hh:mm:ss" )
    @Column( name = "creationdate" )
    private Date creationDate;

    @Column( name = "creationby" )
    private String creationBy;

    @JsonFormat( pattern = "dd-MM-yyyy hh:mm:ss" )
    @Column( name = "updatedate" )
    private Date updateDate;

    @Column( name = "updateby" )
    private String updateBy;

    public BillingHistory() {

    }

    public BillingHistory(Integer id, UserInfo userInfo, BillingPlans billingPlans, String billAmount,
            String billAction, String billPerformer, String billReason, String paymentMethod, String cash,
            String creditcardName, String creditcardNumber, String creditcardType, String creditcardExp, String coupon,
            String discount, String notes, Date creationDate, String creationBy, Date updateDate, String updateBy) {
        super();
        this.id = id;
        this.userInfo = userInfo;
        this.billingPlans = billingPlans;
        this.billAmount = billAmount;
        this.billAction = billAction;
        this.billPerformer = billPerformer;
        this.billReason = billReason;
        this.paymentMethod = paymentMethod;
        this.cash = cash;
        this.creditcardName = creditcardName;
        this.creditcardNumber = creditcardNumber;
        this.creditcardType = creditcardType;
        this.creditcardExp = creditcardExp;
        this.coupon = coupon;
        this.discount = discount;
        this.notes = notes;
        this.creationDate = creationDate;
        this.creationBy = creationBy;
        this.updateDate = updateDate;
        this.updateBy = updateBy;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public UserInfo getUserInfo() {
        return userInfo;
    }

    public void setUserInfo(UserInfo userInfo) {
        this.userInfo = userInfo;
    }

    public BillingPlans getBillingPlans() {
        return billingPlans;
    }

    public void setBillingPlans(BillingPlans billingPlans) {
        this.billingPlans = billingPlans;
    }

    public String getBillAmount() {
        return billAmount;
    }

    public void setBillAmount(String billAmount) {
        this.billAmount = billAmount;
    }

    public String getBillAction() {
        return billAction;
    }

    public void setBillAction(String billAction) {
        this.billAction = billAction;
    }

    public String getBillPerformer() {
        return billPerformer;
    }

    public void setBillPerformer(String billPerformer) {
        this.billPerformer = billPerformer;
    }

    public String getBillReason() {
        return billReason;
    }

    public void setBillReason(String billReason) {
        this.billReason = billReason;
    }

    public String getPaymentMethod() {
        return paymentMethod;
    }

    public void setPaymentMethod(String paymentMethod) {
        this.paymentMethod = paymentMethod;
    }

    public String getCash() {
        return cash;
    }

    public void setCash(String cash) {
        this.cash = cash;
    }

    public String getCreditcardName() {
        return creditcardName;
    }

    public void setCreditcardName(String creditcardName) {
        this.creditcardName = creditcardName;
    }

    public String getCreditcardNumber() {
        return creditcardNumber;
    }

    public void setCreditcardNumber(String creditcardNumber) {
        this.creditcardNumber = creditcardNumber;
    }

    public String getCreditcardType() {
        return creditcardType;
    }

    public void setCreditcardType(String creditcardType) {
        this.creditcardType = creditcardType;
    }

    public String getCreditcardExp() {
        return creditcardExp;
    }

    public void setCreditcardExp(String creditcardExp) {
        this.creditcardExp = creditcardExp;
    }

    public String getCoupon() {
        return coupon;
    }

    public void setCoupon(String coupon) {
        this.coupon = coupon;
    }

    public String getDiscount() {
        return discount;
    }

    public void setDiscount(String discount) {
        this.discount = discount;
    }

    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    public String getCreationBy() {
        return creationBy;
    }

    public void setCreationBy(String creationBy) {
        this.creationBy = creationBy;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public String getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    @Override
    public String toString() {
        return "BillingHistory [id=" + id + ", userInfo=" + userInfo + ", billingPlans=" + billingPlans
                + ", billAmount=" + billAmount + ", billAction=" + billAction + ", billPerformer=" + billPerformer
                + ", billReason=" + billReason + ", paymentMethod=" + paymentMethod + ", cash=" + cash
                + ", creditcardName=" + creditcardName + ", creditcardNumber=" + creditcardNumber + ", creditcardType="
                + creditcardType + ", creditcardExp=" + creditcardExp + ", coupon=" + coupon + ", discount=" + discount
                + ", notes=" + notes + ", creationDate=" + creationDate + ", creationBy=" + creationBy + ", updateDate="
                + updateDate + ", updateBy=" + updateBy + "]";
    }



}

在此查询中我错了..需要建议。

0 个答案:

没有答案