import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
+import org.wamblee.persistence.JpaMergeSupport;
import org.wamblee.usermgt.Group;
import org.wamblee.usermgt.GroupSet;
@Override
public void groupModified(Group aGroup) {
assert aGroup.getPrimaryKey() != null;
- em.merge(aGroup);
+ Group merged = em.merge(aGroup);
+ JpaMergeSupport.merge(merged, aGroup);
}
@Override
/**
* Copies primary keys and version from the result of the merged to the
* object that was passed to the merge operation. It does this by traversing
- * the properties of the object. It copies the primary key and version for
+ * the public properties of the object. It copies the primary key and version for
* objects that implement {@link Persistent} and applies the same rules to
* objects in maps and sets as well (i.e. recursively).
*
for (Method getter : methods) {
if ((getter.getName().startsWith("get") || getter.getName()
.startsWith("is")) &&
- !Modifier.isStatic(getter.getModifiers())) {
+ !Modifier.isStatic(getter.getModifiers()) &&
+ Modifier.isPublic(getter.getModifiers()) &&
+ getter.getParameterTypes().length == 0 &&
+ getter.getReturnType() != Void.class
+ ) {
Class returnType = getter.getReturnType();
try {
return array;
}
}
+
+ private static class X6 {
+ @Id
+ int id;
+
+ public X1 getNotaGetter(String aMessage) {
+ return null;
+ }
+
+ public void getNotaGetter2() {
+
+ }
+ }
+
+ private static class X7 {
+ @Id
+ int id;
+
+ private void getX() {
+ fail("Private getters should not be used");
+ }
+ }
@Test
public void testSimple() {
JpaMergeSupport.merge(x, y);
}
+ @Test
+ public void testNotAGetter() {
+ X6 x = new X6();
+ x.id = 100;
+ X6 y = new X6();
+
+ JpaMergeSupport.merge(x,y);
+ assertEquals(x.id, y.id);
+ }
+
+ @Test
+ public void testPrivateGetter() {
+ X7 x = new X7();
+ x.id = 100;
+ X7 y = new X7();
+ JpaMergeSupport.merge(x,y);
+ assertEquals(x.id, y.id);
+ }
}