I wonder if this is possible with any Nhibernate version.
I have a class A with a property of class B connected by a lazy many-to-one relation. I’d like to get A.B.Id without going to the database (I mean, without getting the whole B entity).
Is this possible?
Thanks!
Just do it! Hibernate is smart enough to not deep-load objects unless you need their other properties, so calling
A.getB().getId()shouldn’t result in the deep-loading of B (it’ll use the id of B stored in A).Here’s a website that explains the concept in a bit more detail: Getting the Id from Lazy Loaded Object Using Annotations in Hibernate
Try it out and see for yourself.