8686import static java .lang .Boolean .parseBoolean ;
8787import static java .lang .Integer .parseInt ;
8888import static java .lang .System .currentTimeMillis ;
89- import static java .util .Collections .unmodifiableMap ;
9089import static org .hibernate .CacheMode .fromJpaModes ;
9190import static org .hibernate .Timeouts .WAIT_FOREVER_MILLI ;
9291import static org .hibernate .cfg .AvailableSettings .CRITERIA_COPY_TREE ;
@@ -2584,13 +2583,14 @@ public LockModeType getLockMode(Object entity) {
25842583 public void setProperty (String propertyName , Object value ) {
25852584 checkOpen ();
25862585 if ( value instanceof Serializable ) {
2587- if ( propertyName != null ) { // store property for future reference:
2586+ if ( propertyName != null ) {
2587+ // store property for future reference
25882588 if ( properties == null ) {
2589- properties = computeCurrentProperties ();
2589+ properties = getInitialProperties ();
25902590 }
25912591 properties .put ( propertyName , value );
2592- // now actually update the setting
2593- // if it's one that affects this Session
2592+ // now actually update the setting if
2593+ // it's one that affects this Session
25942594 interpretProperty ( propertyName , value );
25952595 }
25962596 else {
@@ -2662,7 +2662,7 @@ private void interpretProperty(String propertyName, Object value) {
26622662 }
26632663 }
26642664
2665- private Map <String , Object > computeCurrentProperties () {
2665+ private Map <String , Object > getInitialProperties () {
26662666 final var map = new HashMap <>( getDefaultProperties () );
26672667 //The FLUSH_MODE is always set at Session creation time,
26682668 //so it needs special treatment to not eagerly initialize this Map:
@@ -2672,10 +2672,15 @@ private Map<String, Object> computeCurrentProperties() {
26722672
26732673 @ Override
26742674 public Map <String , Object > getProperties () {
2675- if ( properties == null ) {
2676- properties = computeCurrentProperties ();
2677- }
2678- return unmodifiableMap ( properties );
2675+ // EntityManager Javadoc implies that the
2676+ // returned map should be a mutable copy,
2677+ // not an unmodifiable map. There's no
2678+ // good reason to cache the initial
2679+ // properties, since we have to copy them
2680+ // each time this method is called.
2681+ return properties == null
2682+ ? getInitialProperties ()
2683+ : new HashMap <>( properties );
26792684 }
26802685
26812686 @ Override
0 commit comments