*Entity:* (note the static field is not the property value holder) {code} public class FooEntity { public static final String intValue = "intValue";
private Long id; private Integer _intValue;
public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Integer getIntValue() { return _intValue; } public void setIntValue(Integer intValue) { this._intValue = intValue; } } {code}
*Mapping:* {code} <hibernate-mapping> <class name="FooEntity" table="foo_entity"> <id name="id" type="long"> <generator class="native" /> </id> <property name="intValue" /> </class> </hibernate-mapping> {code}
*Result:* Hibernate internally concludes the type of the property "intValue" is "java.lang.String", and for example creates a table where the column is of type varchar.
*Code:* The debugging of this issue brought me to the following call stack: {code} at PropertyAccessMixedImpl.getAccessType(PropertyAccessMixedImpl.java:107) at PropertyAccessMixedImpl.<init>(PropertyAccessMixedImpl.java:44) at PropertyAccessStrategyMixedImpl.buildPropertyAccess(PropertyAccessStrategyMixedImpl.java:25) at ReflectHelper.getter(ReflectHelper.java:238) at ReflectHelper.reflectedPropertyClass(ReflectHelper.java:218) at SimpleValue.setTypeUsingReflection(SimpleValue.java:481) at ModelBinder.prepareValueTypeViaReflection(ModelBinder.java:2404) {code}
The method _PropertyAccessMixedImpl.getAccessType_ only checks for annotations on the field, but does not check whether or not the field is static, so for our "intValue" it concludes the access type should be FIELD, which seems wrong to me. |
|