Uploaded image for project: 'Hibernate ORM'
  1. HHH-11412

EntityManager/Session setProperty should permit custom properties

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.2.6
    • Fix Version/s: 5.2.8
    • Component/s: hibernate-core
    • Labels:
      None
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true

      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:

      @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).

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: