1

I'm using datanucleus 3.2.7 from Maven, trying to use the Amazon S3 JPA provider. I can successfully write data into S3, but querying either by using "SELECT u FROM User u" or "SELECT u FROM User u WHERE id = :id" causes a NullPointerException to be thrown when I call query.getResultList().

Using the RDBMS provider, everything works perfectly. Is there something I'm doing wrong?

Main.java

    EntityManagerFactory factory = Persistence.createEntityManagerFactory("MyUnit");
    EntityManager entityManager = factory.createEntityManager();
    Query query = entityManager.createQuery("SELECT u FROM User u", User.class);
    List<User> users = query.getResultList(); // Null pointer exception here (This is line 16!)
    for(User u:users)
        System.out.println(u);

User.java

package test;
import javax.persistence.*;

@Entity
@Table(name = "User")
public class User {
    @Id
    public String id;
    public String name;

    public User(String id, String name) {
        this.id = id;
        this.name = name;
    }

    public String toString() {
        return id+" : "+name;
    }
}

persistence.xml

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    version="1.0">

    <persistence-unit name="MyUnit">
        <class>test.User</class>
        <exclude-unlisted-classes />

        <properties>
            <properties>
                <property name="datanucleus.ConnectionURL" value="amazons3:http://s3.amazonaws.com/" />
                <property name="datanucleus.ConnectionUserName" value="xxxxx" />
                <property name="datanucleus.ConnectionPassword" value="xxxxx" />
                <property name="datanucleus.cloud.storage.bucket" value="my-bucket" />
            </properties>
            <property name="datanucleus.autoCreateSchema" value="true" />
        </properties>
    </persistence-unit>
</persistence>

Exception

java.lang.NullPointerException
        at org.datanucleus.NucleusContext.isClassWithIdentityCacheable(NucleusContext.java:1840)
        at org.datanucleus.ExecutionContextImpl.getObjectFromLevel2Cache(ExecutionContextImpl.java:5287)
        at org.datanucleus.ExecutionContextImpl.getObjectFromCache(ExecutionContextImpl.java:5191)
        at org.datanucleus.ExecutionContextImpl.findObject(ExecutionContextImpl.java:3137)
        at org.datanucleus.store.json.CloudStoragePersistenceHandler.getObjectsOfCandidateType(CloudStoragePersistenceHandler.java:367)
        at org.datanucleus.store.json.query.JPQLQuery.performExecute(JPQLQuery.java:94)
        at org.datanucleus.store.query.Query.executeQuery(Query.java:1786)
        at org.datanucleus.store.query.Query.executeWithMap(Query.java:1690)
        at org.datanucleus.api.jpa.JPAQuery.getResultList(JPAQuery.java:194)
        at test.Main.main(Main.java:16)

This error appears to be happening as datanucleus deserializes the JSON for an entry. Deleting everything from the bucket returns the empty set without incident. By turning off L2 Caching, I made the exception occur somewhere else. It seems that ExecutionContextImpl.findObject is being given a null id.

4

1 回答 1

1

datanucleus-json版本3.2.1可能会解决此问题,但需要您确认

于 2013-10-21T14:39:56.857 回答