Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading a list from database using eclipselink jpa

I have three tables in a derby database. Schedule, EmployeeSchedule, EmployeeScheduleInfo. Schedule has a list of EmployeeSchedule and EmployeeSchedule has a list of EmployeeScheduleInfo.

I am using eclipselink jpa and i generated my entities and controllers from netbeans. My problem is when i load a Schedule object from database the list of EmployeeScheduleInfo objects in all EmployeeSchedule objects are not loaded, when i debug this i see

{IndirectList: not instantiated}
like image 332
ddarellis Avatar asked May 03 '26 12:05

ddarellis


1 Answers

1:M and ManyToMany relationships are lazy by default in JPA. That means you need to access the relationship for them to be fetched - call size() on the collection to view it in a debugging environment. You can also prefetch the collection in the initial query using 'fetch join' in the JPQL or an EclipseLink eclipselink.join-fetch query hint: http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Join_Fetch

like image 126
Chris Avatar answered May 05 '26 02:05

Chris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!