gpt4 book ai didi

java - 由 : java. sql.SQLSyntaxErrorException 引起:ORA-01722:JPA HIBERNATE HQL 中的无效数字

转载 作者:行者123 更新时间:2023-11-30 11:09:53 26 4
gpt4 key购买 nike

有这门课

    @Entity
public class PriorityAreaKeyword {

public enum PriorityAreaKey {

ALL ("ALL", "ALL DEVICES"),
IOS ("IOS", "IOS"),
ANDROID ("ANDROID","ANDROID");

private final String name;

private final String id;

private PriorityAreaKey(String name, String id) {
this.name = name;
this.id = id;
}

public String getName() {
return name;
}

public String getId() {
return id;
}
}

@Id
private Long id;

@Column(name = "key")
@Enumerated(EnumType.STRING)
private PriorityAreaKey key;


public Long getId() {
return id;
}

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

public PriorityAreaKey getKey() {
return key;
}

public void setKey(PriorityAreaKey key) {
this.key = key;
}

public List<PriorityArea> getPriorityAreas() {
return priorityAreas;
}

public void setPriorityAreas(List<PriorityArea> priorityAreas) {
this.priorityAreas = priorityAreas;
}
}

我在 DAO 中有这个工作正常的方法:

@Override
@SuppressWarnings("unchecked")
public Set<PriorityArea> findPriorityAreas(PriorityAreaKey key) {

String jpql = "from PriorityAreaKeyword as pak where pak.key = :key";

Query query = entityManager.createQuery(jpql);
query.setParameter("key", key);
List<PriorityArea> priorityAreas = query.getResultList();
return new HashSet<PriorityArea>(priorityAreas);
}

我创建了一个像这样的 View v_report_beneficiary_list (id, email, priority_area_key)

/**
*
*/
@Entity
@Table(name = "v_report_beneficiary_list")
public class ReportBeneficiaryItem {

private Long id;
private String email;
private PriorityAreaKey priorityAreaKey;


/**
* @return the id
*/
@Id
public Long getId() {
return id;
}


/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}



@Column(name = "email")
public String getEmail() {
return email;
}


public void setEmail(String email) {
this.email = email;
}


@Column(name = "priority_area_key")
public PriorityAreaKey getPriorityAreaKey() {
return priorityAreaKey;
}


public void setPriorityAreaKey(PriorityAreaKey priorityAreaKey) {
this.priorityAreaKey = priorityAreaKey;
}

在 DAO 中我创建了另一个这样的方法:

@苏

ppressWarnings("unchecked")
@Override
public List<ReportBeneficiaryItem> findReportProposalXBeneficiary(ProposalExportFilter filter) {

// Create basic query
String jpql = "from " + ReportBeneficiaryItem.class.getName() + " b where b.priorityAreaKey = :key ";

// Create and execute jpa query
Query query = createQuery(jpql);

query.setParameter("key", filter.getPriorityAreaKey());

return query.getResultList();
}

这给我抛出一个异常引起的异常:java.sql.SQLSyntaxErrorException:ORA-01722:无效数字

最佳答案

您在 ReportBeneficiaryItem#getPriorityAreaKey() 上缺少 @Enumerated(EnumType.STRING),就像在 PriorityAreaKeyword#key 上一样,所以它是期望数据库中该字段的数字(枚举索引),但找到字符串

@Column(name = "priority_area_key")
@Enumerated(EnumType.STRING)
public PriorityAreaKey getPriorityAreaKey() {
return priorityAreaKey;
}

关于java - 由 : java. sql.SQLSyntaxErrorException 引起:ORA-01722:JPA HIBERNATE HQL 中的无效数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27979857/

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