File tree Expand file tree Collapse file tree 2 files changed +36
-6
lines changed
main/java/org/hibernate/internal
test/java/org/hibernate/jpa/test Expand file tree Collapse file tree 2 files changed +36
-6
lines changed Original file line number Diff line number Diff line change @@ -3568,13 +3568,13 @@ public LockModeType getLockMode(Object entity) {
3568
3568
public void setProperty (String propertyName , Object value ) {
3569
3569
checkOpen ();
3570
3570
3571
- if ( ENTITY_MANAGER_SPECIFIC_PROPERTIES .contains ( propertyName ) ) {
3572
- properties .put ( propertyName , value );
3573
- applyProperties ();
3574
- }
3575
- else {
3576
- log .debugf ( "Trying to set a property which is not supported on entity manager level" );
3571
+ if ( !( value instanceof Serializable ) ) {
3572
+ log .warnf ( "Property '" + propertyName + "' is not serializable, value won't be set." );
3573
+ return ;
3577
3574
}
3575
+
3576
+ properties .put ( propertyName , value );
3577
+ applyProperties ();
3578
3578
}
3579
3579
3580
3580
@ Override
Original file line number Diff line number Diff line change @@ -376,6 +376,33 @@ public void testSetProperty() throws Exception {
376
376
em .close ();
377
377
}
378
378
379
+ @ Test
380
+ public void testSetAndGetUnserializableProperty () throws Exception {
381
+ EntityManager em = getOrCreateEntityManager ();
382
+ try {
383
+ MyObject object = new MyObject ();
384
+ object .value = 5 ;
385
+ em .setProperty ( "MyObject" , object );
386
+ assertFalse ( em .getProperties ().keySet ().contains ( "MyObject" ) );
387
+ }
388
+ finally {
389
+ em .close ();
390
+ }
391
+ }
392
+
393
+ @ Test
394
+ public void testSetAndGetSerializedProperty () throws Exception {
395
+ EntityManager em = getOrCreateEntityManager ();
396
+ try {
397
+ em .setProperty ( "MyObject" , "Test123" );
398
+ assertTrue ( em .getProperties ().keySet ().contains ( "MyObject" ) );
399
+ assertEquals ( "Test123" , em .getProperties ().get ( "MyObject" ) );
400
+ }
401
+ finally {
402
+ em .close ();
403
+ }
404
+ }
405
+
379
406
@ Test
380
407
public void testPersistExisting () throws Exception {
381
408
EntityManager em = getOrCreateEntityManager ();
@@ -460,4 +487,7 @@ public void testEntityNotFoundException() throws Exception {
460
487
}
461
488
}
462
489
490
+ private static class MyObject {
491
+ public int value ;
492
+ }
463
493
}
You can’t perform that action at this time.
0 commit comments