diff --git a/helenus-core.iml b/helenus-core.iml index 42b1cc5..77f2a38 100644 --- a/helenus-core.iml +++ b/helenus-core.iml @@ -11,6 +11,8 @@ + + diff --git a/pom.xml b/pom.xml index fec721c..89abb41 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 net.helenus helenus-core - 2.0.4-SNAPSHOT + 2.0.5-SNAPSHOT jar helenus diff --git a/src/main/java/net/helenus/core/operation/AbstractStatementOperation.java b/src/main/java/net/helenus/core/operation/AbstractStatementOperation.java index c360705..c15b372 100644 --- a/src/main/java/net/helenus/core/operation/AbstractStatementOperation.java +++ b/src/main/java/net/helenus/core/operation/AbstractStatementOperation.java @@ -193,6 +193,7 @@ public abstract class AbstractStatementOperation keys = (pojo instanceof MapExportable) ? ((MapExportable)pojo).toMap().keySet() : null; + Collection properties = entity.getOrderedProperties(); - for (HelenusProperty prop : entity.getOrderedProperties()) { + for (HelenusProperty prop : properties) { - Object value = BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop); - value = sessionOps.getValuePreparer().prepareColumnValue(value, prop); + // Skip properties that are not in the map of the pojo we're storing. This creates a path + // for entity instances to be {in,up}serted without including all columns in the INSERT statement. + if (keys == null || keys.contains(prop.getPropertyName())) { - if (value != null) { - HelenusPropertyNode node = new HelenusPropertyNode(prop, Optional.empty()); - values.add(Fun.Tuple2.of(node, value)); - } + Object value = BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop); + value = sessionOps.getValuePreparer().prepareColumnValue(value, prop); + + if (value != null) { + HelenusPropertyNode node = new HelenusPropertyNode(prop, Optional.empty()); + values.add(Fun.Tuple2.of(node, value)); + } + + } } @@ -102,6 +113,9 @@ public final class InsertOperation extends AbstractOperation addPropertyNode(t._1)); + if (values.isEmpty()) + return null; + if (entity == null) { throw new HelenusMappingException("unknown entity"); } diff --git a/src/main/java/net/helenus/core/reflect/MapperInvocationHandler.java b/src/main/java/net/helenus/core/reflect/MapperInvocationHandler.java index c244666..99b3fd6 100644 --- a/src/main/java/net/helenus/core/reflect/MapperInvocationHandler.java +++ b/src/main/java/net/helenus/core/reflect/MapperInvocationHandler.java @@ -88,7 +88,7 @@ public class MapperInvocationHandler implements InvocationHandler { Object value = src.get(methodName); - if (value == null && src.containsKey(methodName)) { + if (value == null) { Class returnType = method.getReturnType(); diff --git a/src/test/java/net/helenus/test/integration/core/compound/CompondKeyTest.java b/src/test/java/net/helenus/test/integration/core/compound/CompondKeyTest.java index bc448dc..3241cc6 100644 --- a/src/test/java/net/helenus/test/integration/core/compound/CompondKeyTest.java +++ b/src/test/java/net/helenus/test/integration/core/compound/CompondKeyTest.java @@ -54,9 +54,7 @@ public class CompondKeyTest extends AbstractEmbeddedCassandraTest { public String text() { return text; } - - - + } @Before