2011-12-04 5 views
0

GAE/JDOでLong型のIDのリストを照会しようとしています。結果セットでdetachCopyAll()を呼び出すと、次の例外が発生します。 なぜjava.lang.Longは持続不可能なのですか?

org.datanucleus.jdo.exceptions.ClassNotPersistenceCapableException: The class "The class "java.lang.Long" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found." is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data for the class is not found.
at org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:241)
at org.datanucleus.jdo.JDOPersistenceManager.jdoDetachCopy(JDOPersistenceManager.java:1110)
at org.datanucleus.jdo.JDOPersistenceManager.detachCopyAll(JDOPersistenceManager.java:1183)
...

私は、ユーザーオブジェクトの一覧を照会し、それらをうまく切り離すことができます。 Longのようなプリミティブなラッパークラスはすべて永続性があると思っていました。私は間違って何をしていますか?以下は、私が作業しているコードです。

@PersistenceCapable(identityType=IdentityType.APPLICATION, detachable="true") 
public class User 
{ 
    @PrimaryKey 
    @Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY) 
    private Long id; 

    private String email; 
} 

@SuppressWarnings("unchecked") 
public static List<Long> getUserKeys(String email) 
{ 
    assert email != null; 
    List<Long> keyList = null; 
    PersistenceManager pm = null; 
    Query query = null; 
    try { 
     pm = PMF.get().getPersistenceManager();  
     query = pm.newQuery("select id from " + User.class.getName()); 
     query.declareParameters("String emailParam"); 
     query.setFilter("email == emailParam"); 
     List<Long> resultList = (List<Long>) query.execute(email);   

     // next line causes the ClassNotPersistenceCapableException 
     keyList = (List<Long>) pm.detachCopyAll(resultList); 
    } 
    finally { 
     if (query != null) query.closeAll(); 
     if (pm != null) pm.close(); 
    } 

    return keyList; 
} 

答えて

1
List<Long> resultList = (List<Long>) query.execute(email);   

    // next line causes the ClassNotPersistenceCapableException 
    keyList = (List<Long>) pm.detachCopyAll(resultList); 

私はあなたがここで何をしているかを理解していません。 List<Long>を取り外す必要はありません。 Userエンティティクラスのインスタンスをデタッチする必要がありますが、LongはLongです。​​を使用して、必要な処理を行うことができます。

エラーメッセージは混乱しますが、Longがエンティティクラスではないことが原因です。

+0

実際にロングは取り外す必要があります。それ以外の場合は、PersistenceManagerが閉じられた後にクエリのデータを使用しようとすると、次の例外が発生します。それを試してみてください。 'org.datanucleus.exceptions.NucleusUserException:Object Managerが閉じられました。 ' リストをデタッチできないため、ループ内で手動で要素をコピーする必要があります。 これはDataNucleusの監視のようです。 – KenSV

+0

あなたはロングを外していません。 detachCopyAllに渡されるオブジェクトは、JDO specやDataNucleusのドキュメントやThiloの返信などの永続型でなければなりません。 – DataNucleus

+0

'List 'をデタッチする必要がない場合は、オブジェクトマネージャを使用しようとすると例外が発生するのはなぜですか? – KenSV