eventId and userId are fks in slideshow table. By default User and Event should be lazy loaded to SlideShow by proxy. Hence, I should be able to get eventId and userId from slideShow.getEvent().getEventId() However, the eventId is null when I step through the proxy object in debugger. Same is true for userId. Am I missing something? Should the proxy object has the id of the associate object loaded lazily? How does one retrieve it? Thank you for all your help.
If getEvent works without giving you a lazyloading exception, then you should get the eventId. Calling getEvent within an open session will force Hibernate to load the entity for you.
Yes, that's the code. Does whether lazy initialization happened depends on the default of the mapping? ie. @ManyToOne default lazy so it will get exception; @OneToOne won't because default is eager. What determine if hibernate will run the extra select to get the association. I am still a little confused with any solid rule.
Thank you very much for your answer. I am a big fan of your book. It is my "the book" for for me in using hibernate. I get more every time I read it over.
Assuming everything is lazy, the slideshow will be pulled from the db when it is requested the first time, but the event will not. When the event is first called with a getter, it should be pulled with all of its attributes. So, if getEvent() doesn't return null, the event must have been loaded. If getEvent().getEventId() returns null, the event is not null, but for some reason the eventId is.
Thanks for the kind words about the book!
-Cameron McKenzie
Make yourself as serene as a flower, as a tree. And on wednesdays, as serene as this tiny ad:
a bit of art, as a gift, the permaculture playing cards