NullPointerException using datanucleus-json with S3
Posted
by
Matt
on Stack Overflow
See other posts from Stack Overflow
or by Matt
Published on 2013-10-19T21:49:52Z
Indexed on
2013/10/19
21:53 UTC
Read the original article
Hit count: 304
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.
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
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)
© Stack Overflow or respective owner