We're updating the issue view to help you get more done. 

EntityManager/Session setProperty should permit custom properties

Description

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:

1 2 3 4 5 6 7 8 9 10 11 12 @Stateless public class DAO { @Inject LocaleResolver localeResolver; // e.g. request-scoped proxy @PersistenceContext EntityManager entityManager; // ... DAO methods 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).

Environment

None

Status

Assignee

Chris Cranford

Reporter

Giovanni Lovato

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.2.6

Priority

Major