HHH-10851 : Change to check for @Access on field and getter before checking the class containing the attribute
This commit is contained in:
parent
0e6230faf0
commit
570577b653
|
@ -104,10 +104,6 @@ public class PropertyAccessMixedImpl implements PropertyAccess {
|
|||
}
|
||||
|
||||
protected static AccessType getAccessType(Class<?> containerJavaType, String propertyName) {
|
||||
AccessType classAccessType = getAccessTypeOrNull( containerJavaType );
|
||||
if ( classAccessType != null ) {
|
||||
return classAccessType;
|
||||
}
|
||||
Field field = fieldOrNull( containerJavaType, propertyName );
|
||||
AccessType fieldAccessType = getAccessTypeOrNull( field );
|
||||
if ( fieldAccessType != null ) {
|
||||
|
@ -117,6 +113,11 @@ public class PropertyAccessMixedImpl implements PropertyAccess {
|
|||
if ( methodAccessType != null ) {
|
||||
return methodAccessType;
|
||||
}
|
||||
// No @Access on property or field; check to see if containerJavaType has an explicit @Access
|
||||
AccessType classAccessType = getAccessTypeOrNull( containerJavaType );
|
||||
if ( classAccessType != null ) {
|
||||
return classAccessType;
|
||||
}
|
||||
return field != null ? AccessType.FIELD : AccessType.PROPERTY;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ public class MixedAccessTestTask extends AbstractEnhancerTestTask {
|
|||
private static boolean cleanup = false;
|
||||
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[]{TestEntity.class};
|
||||
return new Class<?>[]{TestEntity.class, TestOtherEntity.class};
|
||||
}
|
||||
|
||||
public void prepare() {
|
||||
|
@ -44,6 +44,10 @@ public class MixedAccessTestTask extends AbstractEnhancerTestTask {
|
|||
testEntity.setParamsAsString( "{\"paramName\":\"paramValue\"}" );
|
||||
s.persist( testEntity );
|
||||
|
||||
TestOtherEntity testOtherEntity = new TestOtherEntity( "foo" );
|
||||
testOtherEntity.setParamsAsString( "{\"paramName\":\"paramValue\"}" );
|
||||
s.persist( testOtherEntity );
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.clear();
|
||||
s.close();
|
||||
|
@ -56,10 +60,13 @@ public class MixedAccessTestTask extends AbstractEnhancerTestTask {
|
|||
TestEntity testEntity = s.get( TestEntity.class, "foo" );
|
||||
Assert.assertEquals( "{\"paramName\":\"paramValue\"}", testEntity.getParamsAsString() );
|
||||
|
||||
TestOtherEntity testOtherEntity = s.get( TestOtherEntity.class, "foo" );
|
||||
Assert.assertEquals( "{\"paramName\":\"paramValue\"}", testOtherEntity.getParamsAsString() );
|
||||
|
||||
// Clean parameters
|
||||
cleanup = true;
|
||||
testEntity.setParamsAsString( "{}" );
|
||||
s.persist( testEntity );
|
||||
testOtherEntity.setParamsAsString( "{}" );
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.clear();
|
||||
|
@ -73,6 +80,9 @@ public class MixedAccessTestTask extends AbstractEnhancerTestTask {
|
|||
TestEntity testEntity = s.get( TestEntity.class, "foo" );
|
||||
Assert.assertTrue( testEntity.getParams().isEmpty() );
|
||||
|
||||
TestOtherEntity testOtherEntity = s.get( TestOtherEntity.class, "foo" );
|
||||
Assert.assertTrue( testOtherEntity.getParams().isEmpty() );
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.clear();
|
||||
s.close();
|
||||
|
@ -128,4 +138,56 @@ public class MixedAccessTestTask extends AbstractEnhancerTestTask {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Access( AccessType.FIELD )
|
||||
private static class TestOtherEntity {
|
||||
|
||||
@Id
|
||||
String name;
|
||||
|
||||
@Transient
|
||||
Map<String, String> params = new LinkedHashMap<>();
|
||||
|
||||
public TestOtherEntity(String name) {
|
||||
this();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
protected TestOtherEntity() {
|
||||
}
|
||||
|
||||
public Map<String, String> getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
public void setParams(Map<String, String> params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
@Column( name = "params", length = 4000 )
|
||||
@Access( AccessType.PROPERTY )
|
||||
public String getParamsAsString() {
|
||||
if ( params.size() > 0 ) {
|
||||
// Convert to JSON
|
||||
return "{" + params.entrySet().stream().map(
|
||||
e -> "\"" + e.getKey() + "\":\"" + e.getValue() + "\""
|
||||
).collect( Collectors.joining( "," ) ) + "}";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setParamsAsString(String string) {
|
||||
params.clear();
|
||||
|
||||
try {
|
||||
params.putAll( (Map<String, String>) engine.eval( "Java.asJSONCompatible(" + string + ")" ) );
|
||||
} catch ( ScriptException ignore ) {
|
||||
// JDK 8u60 required --- use hard coded values to pass the test
|
||||
if ( !cleanup ) {
|
||||
params.put( "paramName", "paramValue" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue