DATAJDBC-146 - Excluding id when provided as additional parameter.

If the id of an entity is provided as an additional parameter, i.e. the foreign key to an entity is the primary key, no id column is generated in the insert since it gets generated for the additional parameter.
This commit is contained in:
Jens Schauder
2017-11-01 11:05:50 +01:00
committed by Greg Turnquist
parent 2fbb3b00c7
commit eeafc04fde
2 changed files with 93 additions and 3 deletions

View File

@@ -100,8 +100,15 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy {
additionalParameters.forEach(parameterSource::addValue);
operations.update(sql(domainType).getInsert(idValue == null, additionalParameters.keySet()), parameterSource,
holder);
boolean idValueDoesNotComeFromEntity = //
idValue == null //
|| additionalParameters.containsKey(idProperty.getColumnName());
operations.update( //
sql(domainType).getInsert(idValueDoesNotComeFromEntity, additionalParameters.keySet()), //
parameterSource, //
holder //
);
setIdFromJdbc(instance, holder, persistentEntity);
@@ -202,7 +209,7 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy {
MapSqlParameterSource parameter = new MapSqlParameterSource(property.getReverseColumnName(), rootId);
return (Iterable<T>)operations.query(findAllByProperty, parameter, property.isQualified() //
return (Iterable<T>) operations.query(findAllByProperty, parameter, property.isQualified() //
? getMapEntityRowMapper(property) //
: getEntityRowMapper(actualType));
}