2014-10-08 49 views
0

嘗試從數據存儲實體中獲取數據時發生異常。 這裏是我的代碼:GAE ClassCastException Long不能強制轉換爲

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; 

} 
+0

「DocHeader」是你自己的類嗎? – icza 2014-10-08 12:54:06

+0

是的,這是我自己的class.and我存儲數據使用這個class.when提取數據顯示錯誤 – 2014-10-08 12:55:06

+0

你可以發佈這個類的來源(編輯問題)? – icza 2014-10-08 12:59:19

回答

0

例外

ClassCastException異常長不能轉換翻一番

意味着你至少有一個DocHeader實體保存在數據存儲在您保存它的一個財產是Long號碼,但在你的Java實體中你指定它爲Double並且當您想要查詢它並將其轉換回Java類時,嘗試轉換LongDouble將引發異常。

你可能做使用低級別的數據存儲區API是隻讀的所有DocHeader entitites,並更改Long屬性Double這應該是擺在首位Double,然後重新保存這些實體。或者,如果當前實體不重要(例如測試數據),只需刪除它們。

文檔:Java low-level Datastore API

相關問題