目前,我将包含以下列的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)


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

最佳答案

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

07-26 02:12