[appengine-java] Re: Exception since upgrading to 1.2.5
> I am using JPA btw, so can someone tell me if I need to do in > order make this work again? Why does it work sometimes? Why not look in the log ? It tells you what is detached, when, and why. If a field (and who knows what type this field is ...) is not detached then you can't access it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-java@googlegroups.com To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en -~--~~~~--~~--~--~---
[appengine-java] Re: Exception since upgrading to 1.2.5
Yes, please provide more information if you can. There was a bug fix in 1.2.5 that made queries respect fetch groups, but JPA doesn't have fetch groups so the error you're reporting suggests that something is wrong here. Can you boil it down to a small snippet that reproduces the problem? Thanks, Max On Wed, Sep 9, 2009 at 10:34 PM, datanucleus wrote: > > > I am using JPA btw, so can someone tell me if I need to do in > > order make this work again? Why does it work sometimes? > > Why not look in the log ? It tells you what is detached, when, and > why. If a field (and who knows what type this field is ...) is not > detached then you can't access it. > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-java@googlegroups.com To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en -~--~~~~--~~--~--~---
[appengine-java] Re: Exception since upgrading to 1.2.5
Trying to give you more info on this. - the error appears sometimes, it causes groovytweets.org fail every other request or so - retweets is a Collection of Entity Retweet, part of the Tweet Entity - worked fine before 1.2.5 - I never detached anything... if I need to, can someone provide an example? I did not find a lot searching jpa detaching. There only seems tobe EntityManager.clear() - which detaches everything. Will this work? Here the mapping: Tweet.groovy @OneToMany(mappedBy="tweet") List retweets ReTweet.groovy @ManyToOne Tweet tweet The code that causes the exception is view code. In a controller, I get a couple of tweet instances and then pass them on to the view for rendering: 1 ... 23retweeted by ${tweet.prettyRetweets} ... 26 wrote: > Yes, please provide more information if you can. There was a bug fix in > 1.2.5 that made queries respect fetch groups, but JPA doesn't have fetch > groups so the error you're reporting suggests that something is wrong here. > Can you boil it down to a small snippet that reproduces the problem? > > Thanks, > Max > > On Wed, Sep 9, 2009 at 10:34 PM, datanucleus wrote: > > > > > > I am using JPA btw, so can someone tell me if I need to do in > > > order make this work again? Why does it work sometimes? > > > Why not look in the log ? It tells you what is detached, when, and > > why. If a field (and who knows what type this field is ...) is not > > detached then you can't access it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-java@googlegroups.com To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en -~--~~~~--~~--~--~---
[appengine-java] Re: Exception since upgrading to 1.2.5
I am not sure what you mean. I never detach anything explicitly, so I have no idea how to detach anything else. >javax.jdo.JDODetachedFieldAccessException: You have just attempted to access field "retweets" yet this field was not detached when you detached the object. Either dont access this field, or detach it when detaching the object. I find that very strange. 1. I am using JPA, how do I get a JDO exception? 2. I never detach anything... so who detaches the main object in this case? Some default behaviour? 3. All I found for detaching reg. JPA is this: In JPA, objects detach automatically when they are serialized or when a persistence context ends. The specification does not define any way to explicitly detach objects. All I found somewhere and I doubt this works on app-engine ( I am not sure which side effects it has, too): EntityManager.clear() - this will detach all objects... --- Would it help if I access the retweets collection right after I queried the datastore? One thing that could be troubling us here is that the view code will call back into the entity objects and then trigger the access of the retweets list. Maybe some context is closed at this point... Cheers Sven On Sep 9, 10:34 pm, datanucleus wrote: > > I am using JPA btw, so can someone tell me if I need to do in > > order make this work again? Why does it work sometimes? > > Why not look in the log ? It tells you what is detached, when, and > why. If a field (and who knows what type this field is ...) is not > detached then you can't access it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-java@googlegroups.com To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en -~--~~~~--~~--~--~---
[appengine-java] Re: Exception since upgrading to 1.2.5
> I am not sure what you mean. I never detach anything explicitly, so I > have no idea how to detach anything else. Yes you do ... in JPA at commit or at close of the EntityManager the contract is to detach all current entities, as per the JPA spec. As you identified later in your post. > >javax.jdo.JDODetachedFieldAccessException: You have just attempted to > access field "retweets" yet this field was not detached when you > detached the object. Either dont access this field, or detach it when > detaching the object. > > I find that very strange. > 1. I am using JPA, how do I get a JDO exception? Because the JPA spec doesn't define the behaviour of accessing an undetached field of a detached object so we can throw whatever we want. We could throw something DataNucleus specific but then what's the point ? In some implementations they do nothing and return null, so the user has no real expectation here. Symptoms of a poor spec ... JPA2 will provide a detach method, when the spec is final ... --Andy (DataNucleus) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-java@googlegroups.com To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en -~--~~~~--~~--~--~---
[appengine-java] Re: Exception since upgrading to 1.2.5
Andy, first of all thx for the response. Things begin to make a little more sense. But still how do I solve my specific issue then. Is the solution to access the retweets field within the JPA callback in this case (as outside it counts as a 'commit' ?? This is the groovy / grails code used in this case. I could try to access the retweets at XXX and then save the result in another, transient field... but this is really ugly. def tweetInstanceList =[] 38 jpaTemplate.execute( { entityManager -> 39 def query = entityManager.createQuery("select tweet from org.groovytweets.Tweet tweet order by tweet.statusId desc") 40 query.maxResults = 50 41 tweetInstanceList = query.resultList XXX 42 } as JpaCallback ) --- So detaching retweets seems like the best. But how? If you are saying JPA1 does not allow this, it means there is no way for me to make this nice? Cheers Sven On Fri, Sep 11, 2009 at 12:43 PM, datanucleus wrote: > >> I am not sure what you mean. I never detach anything explicitly, so I >> have no idea how to detach anything else. > > Yes you do ... in JPA at commit or at close of the EntityManager the > contract is to detach all current entities, as per the JPA spec. As > you identified later in your post. > >> >javax.jdo.JDODetachedFieldAccessException: You have just attempted to >> access field "retweets" yet this field was not detached when you >> detached the object. Either dont access this field, or detach it when >> detaching the object. >> >> I find that very strange. >> 1. I am using JPA, how do I get a JDO exception? > > Because the JPA spec doesn't define the behaviour of accessing an > undetached field of a detached object so we can throw whatever we > want. We could throw something DataNucleus specific but then what's > the point ? In some implementations they do nothing and return null, > so the user has no real expectation here. Symptoms of a poor spec ... > > > JPA2 will provide a detach method, when the spec is final ... > > --Andy (DataNucleus) > > > -- Sven Haiges sven.hai...@googlemail.com Yahoo Messenger / Skype: hansamann Personal Homepage, Wiki & Blog: http://www.svenhaiges.de Subscribe to the Grails Podcast: http://www.grailspodcast.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-java@googlegroups.com To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en -~--~~~~--~~--~--~---
[appengine-java] Re: Exception since upgrading to 1.2.5
Related: why are child objects not automatically detached if the parent is detached? Would that not not logical? Cheers Sven On Fri, Sep 11, 2009 at 12:51 PM, Sven Haiges wrote: > Andy, first of all thx for the response. Things begin to make a little > more sense. > > But still how do I solve my specific issue then. Is the solution to > access the retweets field within the JPA callback in this case (as > outside it counts as a 'commit' ?? > > This is the groovy / grails code used in this case. I could try to > access the retweets at XXX and then save the result in another, > transient field... but this is really ugly. > > def tweetInstanceList =[] > 38 jpaTemplate.execute( { entityManager -> > 39 def query = entityManager.createQuery("select tweet > from org.groovytweets.Tweet tweet order by tweet.statusId desc") > 40 query.maxResults = 50 > 41 tweetInstanceList = query.resultList > XXX > 42 } as JpaCallback ) > > > --- > > So detaching retweets seems like the best. But how? If you are saying > JPA1 does not allow this, it means there is no way for me to make this > nice? > > Cheers > Sven > > On Fri, Sep 11, 2009 at 12:43 PM, datanucleus > wrote: >> >>> I am not sure what you mean. I never detach anything explicitly, so I >>> have no idea how to detach anything else. >> >> Yes you do ... in JPA at commit or at close of the EntityManager the >> contract is to detach all current entities, as per the JPA spec. As >> you identified later in your post. >> >>> >javax.jdo.JDODetachedFieldAccessException: You have just attempted to >>> access field "retweets" yet this field was not detached when you >>> detached the object. Either dont access this field, or detach it when >>> detaching the object. >>> >>> I find that very strange. >>> 1. I am using JPA, how do I get a JDO exception? >> >> Because the JPA spec doesn't define the behaviour of accessing an >> undetached field of a detached object so we can throw whatever we >> want. We could throw something DataNucleus specific but then what's >> the point ? In some implementations they do nothing and return null, >> so the user has no real expectation here. Symptoms of a poor spec ... >> >> >> JPA2 will provide a detach method, when the spec is final ... >> >> --Andy (DataNucleus) >> >> >> > > > > -- > Sven Haiges > sven.hai...@googlemail.com > > Yahoo Messenger / Skype: hansamann > Personal Homepage, Wiki & Blog: http://www.svenhaiges.de > > Subscribe to the Grails Podcast: > http://www.grailspodcast.com > -- Sven Haiges sven.hai...@googlemail.com Yahoo Messenger / Skype: hansamann Personal Homepage, Wiki & Blog: http://www.svenhaiges.de Subscribe to the Grails Podcast: http://www.grailspodcast.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-java@googlegroups.com To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en -~--~~~~--~~--~--~---
[appengine-java] Re: Exception since upgrading to 1.2.5
> Related: why are child objects not automatically detached if the > parent is detached? Would that not not logical? JPA doesn't have "fetch groups" as such, just a "default fetch group". This is defined by which fields are EAGER loaded. So if you had your field marked as EAGER then it would be detached. By default 1-N fields are LAZY hence not detached. The reason we don't just detach child objects is that of where do you stop ? Detach a full object graph ? That'd hammer the performance on some graphs, hence done using the fetch groups etc. Try accessing the field before the detach. The log will tell you whether/when it is detached. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-java@googlegroups.com To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en -~--~~~~--~~--~--~---
[appengine-java] Re: Exception since upgrading to 1.2.5
Thanx, I will try this out tonight as soon as I get access to the code again. It seems making the fetchType EAGER is best, as I will access the filed in all cases, so there is no processing wasted I guess. Out of my head, this would be the solution I guess (changing to FetchType.EAGER, LAZY was default) @OneToMany(mappedBy="tweet", fetch=FetchType.EAGER) List retweets Thanx for your time, I will update this thread later with the result. Cheerrs Sven On Fri, Sep 11, 2009 at 1:14 PM, datanucleus wrote: > >> Related: why are child objects not automatically detached if the >> parent is detached? Would that not not logical? > > JPA doesn't have "fetch groups" as such, just a "default fetch group". > This is defined by which fields are EAGER loaded. So if you had your > field marked as EAGER then it would be detached. By default 1-N fields > are LAZY hence not detached. > > The reason we don't just detach child objects is that of where do you > stop ? Detach a full object graph ? That'd hammer the performance on > some graphs, hence done using the fetch groups etc. > > Try accessing the field before the detach. The log will tell you > whether/when it is detached. > > > > -- Sven Haiges sven.hai...@googlemail.com Yahoo Messenger / Skype: hansamann Personal Homepage, Wiki & Blog: http://www.svenhaiges.de Subscribe to the Grails Podcast: http://www.grailspodcast.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-java@googlegroups.com To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en -~--~~~~--~~--~--~---
[appengine-java] Re: Exception since upgrading to 1.2.5
I was also getting this error after upgrading to 1.2.5, except that in my case the javax.jdo.JDODetachedFieldAccessException was happening when I tried to access a simple 'com.google.appengine.api.datastore.Text' field on a Detached object (Datanucleus must be treating Enumerated fields like a Collection). I'm using JPA, so for every Text in my entities I had to add the annotation @Basic(fetch = FetchType.EAGER). Just FYI, because I'd never used a fetchtype on a non-collection field. Not sure if this is how it's supposed to work, but it fixes the issue. david On Sep 10, 1:13 am, hansamann wrote: > Hi all, > > since I updated my app to the latest java sdk, I sometimes see these > errors (which results in the homepage of the app being blank or > showing an ugly error message): > > [groovytweets/73.336182399219449559].: StackTrace Sanitizing > stacktrace: > org.codehaus.groovy.runtime.InvokerInvocationException: > javax.jdo.JDODetachedFieldAccessException: You have just attempted to > access field "retweets" yet this field was not detached when you > detached the object. Either dont access this field, or detach it when > detaching the object. > at org.codehaus.groovy.reflection.CachedMethod.invoke > (CachedMethod.java:92) > at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234) > at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1062) > at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java: > 926) > at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:893) > at groovy.lang.Closure.call(Closure.java:279) > at org.codehaus.groovy.grails.web.pages.GroovyPage.invokeTag > (GroovyPage.java:219) > at org.codehaus.groovy.grails.web.pages.GroovyPage$invokeTag > $0.callCurrent(Unknown Source) > at > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-java@googlegroups.com To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en -~--~~~~--~~--~--~---