Today I got this error "NucleusUserException: Object Manager has been
closed" in my Spring application. Basically, my application loads some
objects in DAO classes, close the transaction (using Spring declared
transactions) and returns the result to View layer. But when I access
the objects' properties, I got the error. After looking at the
GetFlights.java file (helloorm demo, GAE SDK), I see that the size()
method must be called before closing the transaction. So I changed my
DAO method to:
public List<T> findAll() {
List<T> results = entityManager.createQuery("select o from "
+ getPersistentClass().getName() + " o").getResultList();
results.size(); // In JPA apps, we don't need this call!!
return results;
}
It is working now. But I don't like the idea to call the size()
method. In theory, a JPA application must work with any JPA-compliant
provider. And a JPA application doesn't call size() method just to
load the results from query. So I believe that (DataNucleaus +
appengine plugin) is not a JPA-compliant provider. Please correct me
if I'm wrong.
Why not raise a bug on http://code.google.com/p/datanucleus-appengine/ since DataNucleus itself provides mechanisms for reading in of query
results when a transaction commits. It's likely just not yet
implemented in the plugin yet
> Why not raise a bug onhttp://code.google.com/p/datanucleus-appengine/ > since DataNucleus itself provides mechanisms for reading in of query
> results when a transaction commits. It's likely just not yet
> implemented in the plugin yet
I am also having problems with getResultList() giving
NucleusUserException error. I've tried calling size() as suggested
here, but it doesn't seem to work. Like tha I'm using Spring as well.
public List<Product> getAllProducts() {
String query = "select description, price from
springapp.domain.Product";
List<Product> allProducts = (List<Product>)
entityManager.createQuery(query).getResultList(); // debug: Method
threw 'org.datanucleus.exceptions.NucleusUserException' exception.
allProducts.size(); // debug:
org.datanucleus.exceptions.NucleusUserException: Object Manager has
been closed
return allProducts;
}
At first I thought maybe I haven't set up my entityManager etc
properly (new to Spring) however, finding a product by Id works...so
I'm not quite sure what is happening.
> On Apr 13, 9:27 pm, datanucleus <andy_jeffer...@yahoo.com> wrote:
> > Why not raise a bug onhttp://code.google.com/p/datanucleus-appengine/ > > since DataNucleus itself provides mechanisms for reading in of query
> > results when a transaction commits. It's likely just not yet
> > implemented in the plugin yet
> I am also having problems with getResultList() giving
> NucleusUserException error. I've tried calling size() as suggested
> here, but it doesn't seem to work. Like tha I'm using Spring as well.
> At first I thought maybe I haven't set up my entityManager etc
> properly (new to Spring) however, finding a product by Id works...so
> I'm not quite sure what is happening.
> > On Apr 13, 9:27 pm, datanucleus <andy_jeffer...@yahoo.com> wrote:
> > > Why not raise a bug onhttp://code.google.com/p/datanucleus-appengine/ > > > since DataNucleus itself provides mechanisms for reading in of query
> > > results when a transaction commits. It's likely just not yet
> > > implemented in the plugin yet
> On Apr 18, 8:29 am, pyko <psychop...@gmail.com> wrote:
> > I am also having problems with getResultList() giving
> > NucleusUserException error. I've tried calling size() as suggested
> > here, but it doesn't seem to work. Like tha I'm using Spring as well.
> > At first I thought maybe I haven't set up my entityManager etc
> > properly (new to Spring) however, finding a product by Id works...so
> > I'm not quite sure what is happening.
> > > > Why not raise a bug onhttp://code.google.com/p/datanucleus-appengine/ > > > > since DataNucleus itself provides mechanisms for reading in of query
> > > > results when a transaction commits. It's likely just not yet
> > > > implemented in the plugin yet
> Today I got this error "NucleusUserException: Object Manager has been
> closed" in my Spring application. Basically, my application loads some
> objects in DAO classes, close the transaction (using Spring declared
> transactions) and returns the result to View layer. But when I access
> the objects' properties, I got the error. After looking at the
> GetFlights.java file (helloorm demo, GAE SDK), I see that the size()
> method must be called before closing the transaction. So I changed my
> DAO method to:
> public List<T> findAll() {
> List<T> results = entityManager.createQuery("select o from "
> + getPersistentClass().getName() + " o").getResultList();
> results.size(); // In JPA apps, we don't need this call!!
> return results;
> }
> It is working now. But I don't like the idea to call the size()
> method. In theory, a JPA application must work with any JPA-compliant
> provider. And a JPA application doesn't call size() method just to
> load the results from query. So I believe that (DataNucleaus +
> appengine plugin) is not a JPA-compliant provider. Please correct me
> if I'm wrong.
I don't think this is a bug; it's just designed this way. Very often
it makes sense to close the connection (or object manager) with the
underlying data source (be it Googles datasore or a relational
database) after retrieving the results. However, the combination of a
web application and lazy loading (only retrieving data when you
actually need it) creates this problem and therefor we need some
mechanism to keep the connection open. Thus the
OpenPersistenceManagerInViewFilter.
Gr. Arjan
On Apr 26, 7:45 pm, charpentier damien <damien.charpent...@gmail.com>
wrote:
> It's solved with your "trick", so this is a bug ?
> Regards.
> On 13 avr, 16:01, tha <hathanht...@gmail.com> wrote:
> > Hi all,
> > Today I got this error "NucleusUserException: Object Manager has been
> > closed" in my Spring application. Basically, my application loads some
> > objects in DAO classes, close the transaction (using Spring declared
> > transactions) and returns the result to View layer. But when I access
> > the objects' properties, I got the error. After looking at the
> > GetFlights.java file (helloorm demo, GAE SDK), I see that the size()
> > method must be called before closing the transaction. So I changed my
> > DAO method to:
> > public List<T> findAll() {
> > List<T> results = entityManager.createQuery("select o from "
> > + getPersistentClass().getName() + " o").getResultList();
> > results.size(); // In JPA apps, we don't need this call!!
> > return results;
> > }
> > It is working now. But I don't like the idea to call the size()
> > method. In theory, a JPA application must work with any JPA-compliant
> > provider. And a JPA application doesn't call size() method just to
> > load the results from query. So I believe that (DataNucleaus +
> > appengine plugin) is not a JPA-compliant provider. Please correct me
> > if I'm wrong.