Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 031129e46199fa8ce3c012a5185b455dfd6933eb 1 parent e5c6af6
Oliver Gierke authored June 06, 2012
14  ...g-data-commons-core/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java
... ...
@@ -1,11 +1,11 @@
1 1
 /*
2  
- * Copyright (c) 2011 by the original author(s).
  2
+ * Copyright 2011-2012 the original author or authors.
3 3
  *
4 4
  * Licensed under the Apache License, Version 2.0 (the "License");
5 5
  * you may not use this file except in compliance with the License.
6 6
  * You may obtain a copy of the License at
7 7
  *
8  
- *     http://www.apache.org/licenses/LICENSE-2.0
  8
+ *      http://www.apache.org/licenses/LICENSE-2.0
9 9
  *
10 10
  * Unless required by applicable law or agreed to in writing, software
11 11
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,13 +13,11 @@
13 13
  * See the License for the specific language governing permissions and
14 14
  * limitations under the License.
15 15
  */
16  
-
17 16
 package org.springframework.data.mapping.model;
18 17
 
19 18
 import java.beans.PropertyDescriptor;
20 19
 import java.lang.annotation.Annotation;
21 20
 import java.lang.reflect.Field;
22  
-import java.lang.reflect.Modifier;
23 21
 import java.util.ArrayList;
24 22
 import java.util.List;
25 23
 import java.util.Map;
@@ -34,7 +32,7 @@
34 32
 /**
35 33
  * Simple impementation of {@link PersistentProperty}.
36 34
  * 
37  
- * @author Jon Brisbin <jbrisbin@vmware.com>
  35
+ * @author Jon Brisbin
38 36
  * @author Oliver Gierke
39 37
  */
40 38
 public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>> implements PersistentProperty<P> {
@@ -127,8 +125,12 @@ public String getSpelExpression() {
127 125
 		return null;
128 126
 	}
129 127
 
  128
+	/*
  129
+	 * (non-Javadoc)
  130
+	 * @see org.springframework.data.mapping.PersistentProperty#isTransient()
  131
+	 */
130 132
 	public boolean isTransient() {
131  
-		return Modifier.isTransient(field.getModifiers());
  133
+		return false;
132 134
 	}
133 135
 
134 136
 	/* 
30  ...mmons-core/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java
... ...
@@ -1,3 +1,18 @@
  1
+/*
  2
+ * Copyright 2011-2012 the original author or authors.
  3
+ *
  4
+ * Licensed under the Apache License, Version 2.0 (the "License");
  5
+ * you may not use this file except in compliance with the License.
  6
+ * You may obtain a copy of the License at
  7
+ *
  8
+ *      http://www.apache.org/licenses/LICENSE-2.0
  9
+ *
  10
+ * Unless required by applicable law or agreed to in writing, software
  11
+ * distributed under the License is distributed on an "AS IS" BASIS,
  12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13
+ * See the License for the specific language governing permissions and
  14
+ * limitations under the License.
  15
+ */
1 16
 package org.springframework.data.mapping.model;
2 17
 
3 18
 import static org.hamcrest.Matchers.*;
@@ -13,6 +28,7 @@
13 28
 import org.junit.Test;
14 29
 import org.springframework.data.mapping.Association;
15 30
 import org.springframework.data.mapping.PersistentEntity;
  31
+import org.springframework.data.mapping.PersistentProperty;
16 32
 import org.springframework.data.util.ClassTypeInformation;
17 33
 import org.springframework.data.util.TypeInformation;
18 34
 import org.springframework.util.ReflectionUtils;
@@ -94,8 +110,21 @@ public void considersPropertiesEqualIfFieldEquals() {
94 110
 		assertThat(firstProperty.hashCode(), is(secondProperty.hashCode()));
95 111
 	}
96 112
 
  113
+	/**
  114
+	 * @see DATACMNS-180
  115
+	 */
  116
+	@Test
  117
+	public void doesNotConsiderJavaTransientFieldsTransient() {
  118
+
  119
+		Field transientField = ReflectionUtils.findField(TestClassComplex.class, "transientField");
  120
+
  121
+		PersistentProperty<?> property = new SamplePersistentProperty(transientField, null, entity, typeHolder);
  122
+		assertThat(property.isTransient(), is(false));
  123
+	}
  124
+
97 125
 	class Generic<T> {
98 126
 		T genericField;
  127
+
99 128
 	}
100 129
 
101 130
 	class FirstConcrete extends Generic<String> {
@@ -117,6 +146,7 @@ public void considersPropertiesEqualIfFieldEquals() {
117 146
 		TestClassSet testClassSet;
118 147
 		Map map;
119 148
 		Collection collection;
  149
+		transient Object transientField;
120 150
 	}
121 151
 
122 152
 	class SamplePersistentProperty extends AbstractPersistentProperty<SamplePersistentProperty> {

0 notes on commit 031129e

Please sign in to comment.
Something went wrong with that request. Please try again.