HHH-11412 - EntityManager/Session setProperty should permit custom properties
This commit is contained in:
parent
6b2176ab83
commit
68e1dfffd2
|
@ -3568,13 +3568,13 @@ public final class SessionImpl
|
|||
public void setProperty(String propertyName, Object value) {
|
||||
checkOpen();
|
||||
|
||||
if ( ENTITY_MANAGER_SPECIFIC_PROPERTIES.contains( propertyName ) ) {
|
||||
properties.put( propertyName, value );
|
||||
applyProperties();
|
||||
}
|
||||
else {
|
||||
log.debugf( "Trying to set a property which is not supported on entity manager level" );
|
||||
if ( !( value instanceof Serializable ) ) {
|
||||
log.warnf( "Property '" + propertyName + "' is not serializable, value won't be set." );
|
||||
return;
|
||||
}
|
||||
|
||||
properties.put( propertyName, value );
|
||||
applyProperties();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -376,6 +376,33 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
|
|||
em.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAndGetUnserializableProperty() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
try {
|
||||
MyObject object = new MyObject();
|
||||
object.value = 5;
|
||||
em.setProperty( "MyObject", object );
|
||||
assertFalse( em.getProperties().keySet().contains( "MyObject" ) );
|
||||
}
|
||||
finally {
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAndGetSerializedProperty() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
try {
|
||||
em.setProperty( "MyObject", "Test123" );
|
||||
assertTrue( em.getProperties().keySet().contains( "MyObject" ) );
|
||||
assertEquals( "Test123", em.getProperties().get( "MyObject" ) );
|
||||
}
|
||||
finally {
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersistExisting() throws Exception {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
|
@ -460,4 +487,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
private static class MyObject {
|
||||
public int value;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue