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) 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:
@Stateless
public class DAO {
@Inject LocaleResolver localeResolver;
@PersistenceContext entityManager;
EntityManager getEntityManager() {
this.entityManager.setProperty("current-locale", this.localeResolver.resolve());
return this.entityManager;
}
}
and then retrieve "current-locale" value in an event listener (e.g. PreInsert and PostLoad). |