@Override public void mapToEntityFromMap( EnversService enversService, Object obj, Map data, Object primaryKey, AuditReaderImplementor versionsReader, Number revision) { if (data == null || obj == null) { return; } final Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyData, enversService.getServiceRegistry()); final Object value = data.get(propertyData.getName()); // We only set a null value if the field is not primite. Otherwise, we leave it intact. if (value != null || !isPrimitive(setter, propertyData, obj.getClass())) { setter.set(obj, value, null); } }
private boolean isPrimitive(Setter setter, PropertyData propertyData, Class<?> cls) { if (cls == null) { throw new HibernateException("No field found for property: " + propertyData.getName()); } if (setter instanceof SetterFieldImpl) { // In a direct setter, getMethod() returns null // Trying to look up the field try { return cls.getDeclaredField(propertyData.getBeanName()).getType().isPrimitive(); } catch (NoSuchFieldException e) { return isPrimitive(setter, propertyData, cls.getSuperclass()); } } else { return setter.getMethod().getParameterTypes()[0].isPrimitive(); } }