Я использую аннотацию org.springframework.data.jpa.repository.Query для заполнения набора результатов с использованием данных spring jpa. У меня есть таблица billing history со столбцом creationdate. Я хочу использовать запрос sqldate 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 );
здесь я также пробовал тип данных String для параметров from и 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)!
*****РЕДАКТИРОВАТЬ*****
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 + "]";
}
}
где я ошибаюсь в этом запросе .. нужен совет.
какой тип данных в вашем pojo?
@mrkernelpanic Сейчас я включил класс сущности.
Я думаю, что разобрался в проблеме, скоро прокомментирую .. Я считаю глупую ошибку .. подождите ..
То, что вы разместили здесь, не является вашим реальным кодом. Вы используете String для всех параметров, что не соответствует типам в вашей сущности. Следовательно, сгенерированный запрос не может быть подтвержден как действительный.
@ M.Deinum нет, братан, на самом деле я использую параметр Date для обоих параметров, то есть from и to. Я сказал, что пытался сделать их String, но проблема не решалась. На самом деле глупая ошибка заключалась в следующем: в классе Entity у меня есть переменная creationDate, где, как и в аннотации @Query, я использовал creationdate, см., Это чувствительная проблема с case .. Теперь я решил свою проблему. спасибо stackoverflow выродки
Это не то, о чем говорится в вашем сообщении об ошибке. Следовательно, опубликованный вами код - это не тот код, который вы использовали для создания исключения. В следующих вопросах укажите правильное исключение, относящееся к используемому вами коду.




Похоже, это неверный запрос JPQL. Можете ли вы опубликовать свой объект BillingHistory?