gpt4 book ai didi

java - 无法在类 JPA 上找到合适的构造函数

转载 作者:行者123 更新时间:2023-11-29 04:43:46 25 4
gpt4 key购买 nike

我收到以下错误:

java.lang.IllegalArgumentException: org.hibernate.QueryException: unexpected char:

SELECT NEW com.classes.applicant.ApplicantEntry(app.indSsn, app.indivName, app.indAddrLocTx,app.indAddrCityNm,app.indAdrStateAb,app.indAddrZipCd, app.phoneNr,app.workPhoneNr) FROM TApplicant app WHERE app.indSsn = :ssn

构造函数类是正确的:

public ApplicantEntry(String indSsn, String indivName, String indAddrLocTx, String indAddrCityNm, String indAdrStateAb, String indAddrZipCd,
String phoneNr, String workPhoneNr) {
this.indSsn = indSsn;
this.indivName = indivName;
this.indAddrLocTx = indAddrLocTx;
this.indAddrCityNm = indAddrCityNm;
this.indAdrStateAb = indAdrStateAb;
this.indAddrZipCd = indAddrZipCd;
this.phoneNr = phoneNr;
this.workPhoneNr = workPhoneNr;

}

和实体:

@Entity
@Table(name = "T_APPLICANT", schema = "APP")
public class TApplicant implements Serializable, Applicant {
private static final long serialVersionUID = 1L;

@Id
@Column(name = "IND_SSN", columnDefinition = "CHAR")
private String indSsn;

我不明白为什么它在接收所有字符串时提示它期望所有字符串。

我在 intellij 的持久化工具中运行查询。

存储库中的完整查询:

@Query("SELECT NEW com.classes.applicant.ApplicantEntry(app.indSsn, app.indivName, "
+"app.indAddrLocTx,app.indAddrCityNm,app.indAdrStateAb,app.indAddrZipCd, app.phoneNr,app.workPhoneNr) "
+"FROM TApplicant app "
+"WHERE app.indSsn = :ssn ")
ApplicantEntry getApplicantEntry(@Param("ssn") String ssn);

最佳答案

请注意任何使用 Lombok 的人,类中字段的物理顺序决定了构造函数参数的顺序。类字段的物理顺序必须与 SELECT 子句的顺序相匹配。

@AllArgsConstructor
public class Thing {
private String name;
private Date birthday;
}

// not the same as...

@AllArgsConstructor
public class Thing {
private Date birthday;
private String name;
}

关于java - 无法在类 JPA 上找到合适的构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38102936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com