views:

80

answers:

4
A: 

There could be a problem in your EJB method getPlaceWithId - not sure how you're looking up your entities.

reverendgreen
no, It actually works as expected with hibernate and FetchType.EAGER, there must be some problem with the eclipse link...
coubeatczech
which version of EclipseLink are you using?
reverendgreen
I'm using EclipseLink 2.1.0
coubeatczech
+2  A: 

Are you calling p.getEvents().size() or are you inspecting the attribute in a debugger? If it is in a debugger then you may be seeing the Lazy loading artifacts which will be empty until the collection is accessed. Try calling p.getEvents().get(0) and see what you get.

Gordon Yorke
+1  A: 

1)

@OneToMany(mappedBy = "place", fetch = FetchType.EAGER)
private List<Event> events = new ArrayList<Event>();

does it.

2) or

Place p = ejb.getPlaceWithId(1);
p.getEvents().size(); // will force the fetch
iimuhin
+2  A: 

Now, I would like to pick a place and view all its events (...) and I would think that there's something more than empty collection in p.events, but there is not - based on my observations. Why?

My observations are that the events are LAZY in the code you're showing:

@OneToMany(mappedBy = "place")
private List<Event> events = new ArrayList<Event>();

So how did you come to the conclusion that they are empty when loading a given Place exactly? Did you try to call size() on the collection to force the loading (or to iterate on collection items)?

Regardless of the answer to the above question, my suggestions would be to

  • Activate SQL logging (and to run the queries in a SQL client if necessary) to see what is happening.
  • Maybe actually use a fetch join if you want to load the events eagerly:

    SELECT p FROM Place p join fetch p.events WHERE p.id = :id
    
Pascal Thivent