• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
  • Tim Holloway
  • Carey Brown
  • salvin francis

Lazy relationships become loaded after EntityManager closes

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys

Using JPA 2.0, I do not want that lazy loaded relationships become loaded after closing EntityManager.

This is what I'm using
Netbeans 6.8
PostgreSQL 8.4
EclipseLink 2.0

I mean, If an Entity object has a (lazily loaded) collection of other Entities, I expect that after closing the EntityManager, those relationships are not loaded. I want null fields or a NullPointerException. But what I'm getting after closing the EntityManager is the full node tree.

Class A

Class B

Main Class


As you can see, B may be too big to keep in memory. For example, I want to list all the 500 instances of A. And each A has 100 B, so I have a total of 5000 B objects. I want ONLY the list of A, without their B's loaded. But I'm getting all the 500 A's and all the 5000 B's.

Am I missing some point?

Thank you guys
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is odd that you would want a null-pointer exception when accessing your relationship instead of its value.

If you do not wish to have the value instantiated, then do not access it.

Otherwise, you could clone or serialize the object and leave the lazy relationship as null.
Too many men are afraid of being fools - Henry Ford. Foolish tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!