gpt4 book ai didi

java - 执行 SELECT 查询时出现 ClassCastException

转载 作者:行者123 更新时间:2023-12-01 14:41:56 25 4
gpt4 key购买 nike

目前,我将包含以下列的 CSV 文件上传到 Google App Engine 数据存储区:

id, roleName, eggName, highestAllTimePrice, lowestAllTimePrice, averagePrice

当我访问localhost:8888/_ah/admin/datastore时,表的结果如下:

Key, Write Ops, ID/Name, averagePrice, eggName, eggNumber, highestAllTimePrice, lowestAllTimePrice, roleName

我从表中获取所有数据如下:

public String GetData(final ModelMap model)
{
EntityManager em = EMF.get().createEntityManager();
Query q = em.createQuery("SELECT s FROM Egg s");
List<Egg> eggs = new ArrayList<Egg>(q.getResultList());

model.addAttribute("eggs", eggs);
return "index";
}

实体

@Entity
public class Egg {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key key;

private int eggNumber;
private String roleName;
private String eggName;
private double highestPrice;
private double lowestPrice;
private double averagePrice;

// getters setters
}

但是当我运行该查询时,我收到此错误:

java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Double
at com.google.appengine.datanucleus.FetchFieldManager.fetchDoubleField(FetchFieldManager.java:140)
at org.datanucleus.state.AbstractStateManager.replacingDoubleField(AbstractStateManager.java:2256)
at Entity.Egg.jdoReplaceField(Egg.java)
at Entity.Egg.jdoReplaceFields(Egg.java)

问题是我不知道为什么要转换类型?我的实体类映射错误了吗?

最佳答案

也许您的双字段(highestPrice 等)被视为数据存储中的字符串,因此无法映射到您的实体。

关于java - 执行 SELECT 查询时出现 ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15864044/

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