> While it should be perfectly fine if not all testentities have children (size() should just return 0) correct... I need another cup of coffee :)
> Weird that it works for you...is there anything further I can do to debug this? Agreed. For giggles, try removing the em.merge call. I seem to remember some changes being made in this area. I'm been running on trunk, but I'll try to get a 2.1.x testcase going. On Thu, Aug 4, 2011 at 9:12 AM, Michael Pflueger <michael.pflue...@sma.de>wrote: > While it should be perfectly fine if not all testentities have children > (size() should just return 0), I have dropDB in my persistence.xml, so > tables are dropped and recreated with every run. > > In this example, the call to merge() is indeed unnecessary, but in the real > program I need to read a huge table and thus have to repeatedly clear() the > persistence context so I can keep the memory footprint low. The clear() is > causing all objects to be detached. Im reading this huge table within an > outer loop which traverses another table, and I need to merge those entities > so I can be sure I can access their lazy associations. > > Weird that it works for you...is there anything further I can do to debug > this? > > It seems it fetches the children collection before the NPE, btw... here's a > log: > > > 2344 openjpa TRACE [main] openjpa.Runtime - Query "SELECT * FROM > TestEntity t" is cached." > 2344 openjpa TRACE [main] openjpa.Query - Executing query: Query: > org.apache.openjpa.kernel.QueryImpl@d22462; candidate class: class > test.TestEntity; query: null > 2391 openjpa TRACE [main] openjpa.jdbc.SQL - <t 17284365, conn 16645208> > executing prepstmnt 29806874 SELECT t0.id FROM TestEntity t0 > 2391 openjpa TRACE [main] openjpa.jdbc.SQL - <t 17284365, conn 16645208> > [0 ms] spent > 2406 openjpa TRACE [main] openjpa.jdbc.JDBC - <t 17284365, conn 0> [0 > ms] close > I got 1 entities... > 2422 openjpa TRACE [main] openjpa.jdbc.SQLDiag - load field: 'children' > for oid=328601 class test.TestEntity > 2438 openjpa TRACE [main] openjpa.jdbc.SQL - <t 17284365, conn 16645208> > executing prepstmnt 1497769 SELECT t0.id FROM TestEntity2 t0 WHERE > t0.PARENT_ID = ? [params=(int) 328601] > 2438 openjpa TRACE [main] openjpa.jdbc.SQL - <t 17284365, conn 16645208> > [0 ms] spent > 2438 openjpa TRACE [main] openjpa.jdbc.JDBC - <t 17284365, conn 0> [0 > ms] close > Exception in thread "main" java.lang.NullPointerException > at test.Test.main(Test.java:41) > > > > regards, > Michael > > > > -----Ursprüngliche Nachricht----- > Von: Rick Curtis [mailto:curti...@gmail.com] > Gesendet: Donnerstag, 4. August 2011 16:00 > An: users@openjpa.apache.org > Betreff: Re: NullpointerException when accessing a lazy association after > merging the object without a fetch of the lazy entities > > I don't see any issues. Is it possible that you have a TestEntity in your > DB > that doesn't have any children (bad data) in your DB from a previous run? > > Also, why are you calling em.merge(..)? That call is unnecessary as the > results from your query already are a part of your persistence context. > > Thanks, > Rick > > ___________________________________________________ > > SMA Solar Technology AG > Aufsichtsrat: Guenther Cramer (Vorsitzender) > Vorstand: Juergen Dolle, Roland Grebe, Uwe Hertel, Pierre-Pascal Urbon, > Marko Werner > Handelsregister: Amtsgericht Kassel HRB 3972 > Sitz der Gesellschaft: 34266 Niestetal > USt-ID-Nr. DE 113 08 59 54 > WEEE-Reg.-Nr. DE 95881150 > ___________________________________________________ > > -- *Rick Curtis*