目前,我将包含以下列的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)
问题是我不知道为什么转换类型?我是否错误地映射了我的实体类?
答案 0 :(得分:1)
也许您的双字段(highestPrice等)被视为数据存储区中的字符串,因此无法映射到您的实体。