The spec for {{EntityManager.setProperty(String propertyName, Object value)}} says: "Set an entity manager property or hint. If a vendor-specific property or hint is not recognized, it is silently ignored."
This means that vendor-specific (i.e. custom) properties will be silently ignored, but Hibernate Session implementation seems to interpret _ignored_ as _discarded_ (see [SessionImpl.java#L3571|https://github.com/hibernate/hibernate-orm/blob/318473e59caddafa8f38b672f8d38ea6911c696c/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java#L3571]) for no reason.
A developer should have means to set arbitrary objects as properties of a session, to set them at some point and retrieve their values later during the same session. A simple use case:
{code:java} @Stateless public class DAO { @Inject LocaleResolver localeResolver; // i.e. request-scoped proxy @PersistenceContext EntityManager entityManager;
// ... DAO methods
EntityManager getEntityManager() { this.entityManager.setProperty("current-locale", this.localeResolver.resolve()); return this.entityManager; } } {code}
and then retrieve "current-locale" value in an event listener (e.g. {{PreInsert}} and {{PostLoad}}). |
|