我为我的表创建了一个数据类,该数据类在命名查询中引发错误
实体名称与表名称类似。
@Table
@Entity(name = "CKYCUploadTransactions")
@Access(AccessType.FIELD)
@NamedQueries({
@NamedQuery(name = "CKYCUploadTransactions.byUserId", query = "select k from CKYCUploadTransactions k where" +
"k.userId = :user_id"),
@NamedQuery(name = "CKYCUploadTransactions.byUserIdAndTxnTypeAndStatus", query = "select k from CKYCUploadTransactions k where" +
"k.userId = :user_id AND k.txnType = :txn_type AND k.status = :status"),
@NamedQuery(name = "CKYCUploadTransactions.byUserIdAndContext", query = "select k from CKYCUploadTransactions k where" +
"k.userId = :user_id and k.context = :context")
})
@Data
public class CKYCUploadTransactions {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "user_id")
private String userId;
@Column(name = "context")
private String context;
@Column(name = "txn_type")
private String txnType;
@Enumerated(EnumType.STRING)
@Column(name = "status", length = 20)
private Status status;
public enum Status{
initiated,
success,
failed
}
}
我不明白为什么它会抛出此错误,我创建了另一个类似的实体,但没有遇到那里的问题。
异常:命名查询中的错误:CKYCUploadTransactions.byUserIdAndTxnTypeAndStatus、CKYCUploadTransactions.byUserIdAndContext、CKYCUploadTransactions.byUserId
Entity name is similar to name of the table.
@Table
@Entity(name = "CKYCUploadTransactions")
@Access(AccessType.FIELD)
@NamedQueries({
@NamedQuery(name = "CKYCUploadTransactions.byUserId", query = "select k from CKYCUploadTransactions k where" +
"k.userId = :user_id"),
@NamedQuery(name = "CKYCUploadTransactions.byUserIdAndTxnTypeAndStatus", query = "select k from CKYCUploadTransactions k where" +
"k.userId = :user_id AND k.txnType = :txn_type AND k.status = :status"),
@NamedQuery(name = "CKYCUploadTransactions.byUserIdAndContext", query = "select k from CKYCUploadTransactions k where" +
"k.userId = :user_id and k.context = :context")
})
@Data
public class CKYCUploadTransactions {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "user_id")
private String userId;
@Column(name = "context")
private String context;
@Column(name = "txn_type")
private String txnType;
@Enumerated(EnumType.STRING)
@Column(name = "status", length = 20)
private Status status;
public enum Status{
initiated,
success,
failed
}
}
I am not understanding why it is throwing this error, I have created another entity like this but not facing the issues there.
Exception: Errors in named queries: CKYCUploadTransactions.byUserIdAndTxnTypeAndStatus, CKYCUploadTransactions.byUserIdAndContext, CKYCUploadTransactions.byUserId
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以按照此 JPA 命名查询
CKYCUploadTransactions.byUserId
应该是
CKYCUploadTransactions.findByUserId
You can follow this JPA Named Queries
CKYCUploadTransactions.byUserId
should be
CKYCUploadTransactions.findByUserId