Populate child bean with Transformers.aliasToBean in Hibernate

后端 未结 5 1124
太阳男子
太阳男子 2020-12-10 16:53

I have the next couple of beans:

Address {
    String name;
    String number;
    String zipcode;
    String town;
}

MyEntity {
    Address address;
    St         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-10 17:47

    Code provided in Github works fine but there is change in import for new versions of hibernate. Its as follow.

    org.hibernate.property.PropertyAccessor replaced byorg.hibernate.property.access.spi.PropertyAccess

    and

    org.hibernate.property.PropertyAccessorFactory replaced by org.hibernate.property.access.internal.PropertyAccessStrategyBasicImpl

    So you'll have change the code from

    PropertyAccessor accessor = PropertyAccessorFactory.getPropertyAccessor("property");
    accessor.getSetter(resultClass, (String)subclassToAlias.get(subclass).get(2)).set(root, subObject, null);
    

    to

    PropertyAccess propertyAccess = PropertyAccessStrategyBasicImpl.INSTANCE.buildPropertyAccess(resultClass, (String)subclassToAlias.get(subclass).get(2));
    propertyAccess.getSetter().set(root, subObject, null);
    

提交回复
热议问题