aspose file tools
The moose likes Object Relational Mapping and the fly likes Hibernate EntityManager working with Collections Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Hibernate EntityManager working with Collections" Watch "Hibernate EntityManager working with Collections" New topic
Author

Hibernate EntityManager working with Collections

Brian Smith
Ranch Hand

Joined: May 20, 2005
Posts: 63
I have an entity (InvalidAddress) with a many to one relationship with another entity (ServiceRequest). I am trying to add an InvalidAddress entity to the InvalidAddressCollection owned by ServiceRequest



I am getting a NPE because serviceRequest.getInvalidAddressCollection() is returning null when there are no related InvalidAddress entities. I know this makes sense but it seems like a waste to have to do this before I add any related entity to any collection



Is this very repetitive boiler-plate required when working with collections?

It would seem like the EntityManager should initialize the Collection and just return an empty list instead of a null list. Or is that up to me when I implement the getter on ServiceRequest?

Thanks for any advice.
[ July 23, 2007: Message edited by: Brian Smith ]
 
 
subject: Hibernate EntityManager working with Collections
 
Threads others viewed
NullPointer with EntityManager in Entity Bean
How do you update a collection if some exist and some are new?
OpenEntityManagerInView, yet closed session
Inheritance Mapping and Relationships
problem persisting an object with collections and manytomany relationship
IntelliJ Java IDE