How would Hibernate load address instances if you request cities? JPA entities are objects, and objects must perceive invariants. For example, one of such invariants may be that the address always has an identifier, street, etc. If Hibernate loads partial objects (only with a filled city attribute), these invariants will be broken and you will no longer be able to rely on your own code. You would also have all kinds of problems if you tried to attach such an address to another object or just tried to delete because it didnβt even have an identifier.
So, the short answer is no: it is not possible.
The long answer is that since the Address is a POJO, you just need to create Addresses from busy cities on your own or using ResultTransformer. But you will get temporary address addresses, not attached Address objects. This is a recipe for countless errors and confusion, IMHO.
Jb nizet
source share