[英]GAE ClassCastException Long cannot be cast to double
嘗試從數據存儲實體獲取數據時獲取異常。 這是我的代碼:
PersistenceManager pmf = PMF.get().getPersistenceManager();
try {
Query query = pmf.newQuery(DocHeader.class);
@SuppressWarnings("unchecked")
List<DocHeader> docHeaders = (List<DocHeader>) query.execute();
任何人都可以幫助解決此問題。
這是我的對象
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class DocHeader {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.SEQUENCE)
private Long docHeaderId;
@Persistent
private Double previousPayment;
@Persistent
private Double currentBalance;
@Persistent
private Double totalAccountBalance;
@Persistent
private String accountRepresentative;
@Persistent
private Double minPayment;
}
例外
ClassCastException-Long無法轉換為double
表示您在數據存儲區中保存了至少一個DocHeader
實體,並在其中保存了它的一個屬性(即Long
數字),但是在Java實體中將其指定為Double
並且在要查詢並將其轉換回Java類時,嘗試的轉換Long
> Double
引發異常。
您可以做的是使用低級數據存儲區api閱讀所有DocHeader
實體,然后將Long
屬性首先更改為Double
,然后將它們重新保存,該屬性應該是Double
的。 或者,如果當前實體不重要(例如測試數據),則將其刪除。
文檔: Java低級數據存儲區API
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.