• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

fetch eager in google app engine using JPA (datastore)

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have the following JPA-annotated classes:



The B class has no reference to A.

When I try to get an A object using its ID, I get the following error:

You have just attempted to access field "bs" yet this field was not detached when you detached the object. Either dont access this field, or detach it when detaching the object.

Although I read app engine does not support eager fetching (in a 2012 book), I tried adding fetch = FetchType.EAGER to the annotation and it solved the problem, although then I get the following warning:

"The datastore does not support joins and therefore cannot honor requests to place related objects in the default fetch group. The field will be fetched lazily on first access."

The get operation completes successfully anyway.

So, what's up? What would be the best solution for this case? Keep it with the eager annotation? In my get method I have also accessed the bs collection, which brought the data to memory (the n+1 thing) and everything was ok too.

Any comments would be appreciated.

Rodrigo.




 
Rodrigo Bossini
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, the topic has to do with datastore and app engine. Although I'm using JPA, this is not an object RELATIONAL mapping issue since datastore is not relational. If the Web Services forum is not appropriate, the ORM forum sounds even worse for me.
 
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is definitely not about Web Services - I don't see any connection there. But a specific Big Table forum exists: https://coderanch.com/forums/f-129/bigtable You use a ORM API provider but the problems seem to be specific about that product.

I am not sure about the problem itself, sorry. But this part sounds weird:

When I try to get an A object using its ID, I get the following error: You have just attempted to access field "bs" yet this field was not detached



So you get the error when you access the field but getting A itself succeeds? If this is true you need to show more of the transaction and access to the object.
 
Rodrigo Bossini
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At first I put it in the web services forum because I'm actually using google cloud endpoints. Probably the BigTable forum would be a good option indeed.

I can't tell precisely whether or not the A object has been retrieved, but because of the message I'd say it is.

Here is the code I'm using to run the retrieval:

@ApiMethod(name = "getA")
public A getA(@Named("id") String id) {
EntityManager mgr = getEntityManager();
A a = null;
try {
a = mgr.find(A.class, id);
} finally {
mgr.close();
}
return a;
}

Also, here is my persistence unit configuration:

<persistence-unit name="transactions-optional">
<provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
<properties>
<property name="datanucleus.NontransactionalRead" value="true"/>
<property name="datanucleus.NontransactionalWrite" value="true"/>
<property name="datanucleus.ConnectionURL" value="appengine"/>
<property name="datanucleus.appengine.datastoreEnableXGTransactions" value="true"/>
</properties>
</persistence-unit>

The datastoreEnableXGTransactions thing has to do with datastore entity groups. It allows one single transaction to operate over entity from up to 5 groups. At the moment I guess I need it because the B objects, children from A, are uowned. But I'm studying some different options too. Any comments on this would be appreciated.

Rodrigo.
 
Ranch Hand
Posts: 948
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The issue lies with which layer?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic