How to convert a Hibernate proxy to a real entity object

Here’s a method I’m using. public static <T> T initializeAndUnproxy(T entity) { if (entity == null) { throw new NullPointerException(“Entity passed for initialization is null”); } Hibernate.initialize(entity); if (entity instanceof HibernateProxy) { entity = (T) ((HibernateProxy) entity).getHibernateLazyInitializer() .getImplementation(); } return entity; }

EF Core returns null relations until direct access

The reason is explained in the Loading Related Data section of the EF Core documentation. The first behavior is because EF Core currently does not support lazy loading, so normally you’ll get null for navigation properties until you specifically load them via eager or explicit loading. However, the Eager loading section contains the following: Tip … Read more

Why is Hibernate Open Session in View considered a bad practice?

Open Session In View takes a bad approach to fetching data. Instead of letting the business layer decide how it’s best to fetch all the associations that are needed by the View layer, it forces the Persistence Context to stay open so that the View layer can trigger the Proxy initialization. The OpenSessionInViewFilter calls the … Read more

How can I make a JPA OneToOne relation lazy

First off, some clarifications to KLE‘s answer: Unconstrained (nullable) one-to-one association is the only one that can not be proxied without bytecode instrumentation. The reason for this is that owner entity MUST know whether association property should contain a proxy object or NULL and it can’t determine that by looking at its base table’s columns … Read more