I have an entity A which has a one-to-one mapping to another entity B and hibernate is lazy-loading. I want to have it so it is possible to retrieve entity B directly or just entity B's foreign key right from entity A.
public class A{
private long bfk;
private B b;
//setters/getters...
}
The behavior I'm looking for is when I retrieve entity A that bfk would be populated with the correct foreign key value (but b would still not be set). And when I getB() that the proper entity would be retrieved by hibernate. Also from the setting side: when I setB() hibernate would correctly populate idOfB with the foreign key. And when I setBfk() that hibernate would return the correct entity if I then retrieve getB(). Is this possible, preferably with annotations?
Just wanted to add that I think this might be somewhat similar to this question but I want to also have the entity, not just the fk.
Thank you very much in advance.