Почему java.lang.Long не сохраняется? - PullRequest
0 голосов
/ 04 декабря 2011

Я пытаюсь запросить список идентификаторов типа Long в GAE / JDO. И я получаю следующее исключение, когда я вызываю detachCopyAll () для набора результатов. </p> <blockquote> <p>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.<br> at org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:241)<br> at org.datanucleus.jdo.JDOPersistenceManager.jdoDetachCopy(JDOPersistenceManager.java:1110)<br> at org.datanucleus.jdo.JDOPersistenceManager.detachCopyAll(JDOPersistenceManager.java:1183)<br> ...

Я могу запросить список объектов User и просто отсоединить их. Я ожидал, что все примитивные классы-обёртки, такие как 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 Ответ

1 голос
/ 04 декабря 2011
    List<Long> resultList = (List<Long>) query.execute(email);          

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

Я не понимаю, что ты здесь делаешь. A List<Long> не нужно отсоединять. Вы бы хотели отсоединить экземпляры вашего класса сущностей User, но Long - это Long, и вы можете просто делать все, что вам нужно, с resultList.

Сообщение об ошибке сбивает с толку, но просто вызвано тем, что Long не является классом сущности.

...