Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

DATACMNS-180 - Don't consider Java transient fields transient for per…

…sistence.

So far we have considered Java transient fields as transient through the isTransient() method on PersistentProperty. This resulted in the properties not being persisted eventually. We now consider all fields as non-transient by default as we actually have to persist them as the object cannot be re-created completely without doing so as the usage of the transient keyword might rely on the readObject(…) method inside the object which would actually reconstitute the transient field's state but we of course cannot call this method actually.
  • Loading branch information...
commit 9c42393a5141ff7c0485749e7cadb735a3bd268a 1 parent b483cbc
@olivergierke olivergierke authored
View
14 ...g-data-commons-core/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java
@@ -1,11 +1,11 @@
/*
- * Copyright (c) 2011 by the original author(s).
+ * Copyright 2011-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,13 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.springframework.data.mapping.model;
import java.beans.PropertyDescriptor;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -34,7 +32,7 @@
/**
* Simple impementation of {@link PersistentProperty}.
*
- * @author Jon Brisbin <jbrisbin@vmware.com>
+ * @author Jon Brisbin
* @author Oliver Gierke
*/
public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>> implements PersistentProperty<P> {
@@ -127,8 +125,12 @@ public String getSpelExpression() {
return null;
}
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.mapping.PersistentProperty#isTransient()
+ */
public boolean isTransient() {
- return Modifier.isTransient(field.getModifiers());
+ return false;
}
/*
View
30 ...mmons-core/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2011-2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.springframework.data.mapping.model;
import static org.hamcrest.Matchers.*;
@@ -13,6 +28,7 @@
import org.junit.Test;
import org.springframework.data.mapping.Association;
import org.springframework.data.mapping.PersistentEntity;
+import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.ReflectionUtils;
@@ -94,8 +110,21 @@ public void considersPropertiesEqualIfFieldEquals() {
assertThat(firstProperty.hashCode(), is(secondProperty.hashCode()));
}
+ /**
+ * @see DATACMNS-180
+ */
+ @Test
+ public void doesNotConsiderJavaTransientFieldsTransient() {
+
+ Field transientField = ReflectionUtils.findField(TestClassComplex.class, "transientField");
+
+ PersistentProperty<?> property = new SamplePersistentProperty(transientField, null, entity, typeHolder);
+ assertThat(property.isTransient(), is(false));
+ }
+
class Generic<T> {
T genericField;
+
}
class FirstConcrete extends Generic<String> {
@@ -117,6 +146,7 @@ public void considersPropertiesEqualIfFieldEquals() {
TestClassSet testClassSet;
Map map;
Collection collection;
+ transient Object transientField;
}
class SamplePersistentProperty extends AbstractPersistentProperty<SamplePersistentProperty> {
Please sign in to comment.
Something went wrong with that request. Please try again.