I was wondering if there is a way to mark some properties as immutable
value properties, that is, properties that holds values that can't be
modified after creation and, thus, should not be deep copied. An example
unit test below. Basically, there is a SomeId class, which is immutable.
SomeEntity class have a property of SomeId type. Mapping SomeEntity to
another SomeEntity does not copy the id property as I expected it to. It
would be nice to be able to mark the id property of SomeEntity or the
SomeId class as immutable (via annotation or MergingContext) and have java
merger just copy such properties (the same way it does it for String class
and other built in immutables).
I tried to achieve it using PropertyConverter with no success. My current
workaround is to @Skip the id property and to copy it manually after the
mapping, which is kind of ugly.
I was wondering if there is a way to mark some properties as immutable
value properties, that is, properties that holds values that can't be
modified after creation and, thus, should not be deep copied. An example
unit test below. Basically, there is a SomeId class, which is immutable.
SomeEntity class have a property of SomeId type. Mapping SomeEntity to
another SomeEntity does not copy the id property as I expected it to. It
would be nice to be able to mark the id property of SomeEntity or the
SomeId class as immutable (via annotation or MergingContext) and have java
merger just copy such properties (the same way it does it for String class
and other built in immutables).
I tried to achieve it using PropertyConverter with no success. My current
workaround is to @Skip the id property and to copy it manually after the
mapping, which is kind of ugly.
Last edit: Servy 2014-07-07
To make it work as you expected, you should declare SomeId.class as value type in MergingContext. Like this:
mergingContext.setValueTypes(Arrays.asList(SomeId.class));
See javadoc of method 'setValueTypes' for details.
Then costructor with no arguments in SomeId could aslo be removed.