Skip to content

Commit e8f04ec

Browse files
authored
Handle Transient Annotation. (#1173)
Closes #1147. Co-authored-by: mikereiche <[email protected]>
1 parent ae2217d commit e8f04ec

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.springframework.core.CollectionFactory;
3535
import org.springframework.core.convert.ConversionService;
3636
import org.springframework.core.convert.support.DefaultConversionService;
37+
import org.springframework.data.annotation.Transient;
3738
import org.springframework.data.convert.EntityInstantiator;
3839
import org.springframework.data.couchbase.core.mapping.CouchbaseDocument;
3940
import org.springframework.data.couchbase.core.mapping.CouchbaseList;
@@ -532,6 +533,10 @@ public void doWithPersistentProperty(final CouchbasePersistentProperty prop) {
532533
idAttributes.put(order, convertToString(propertyObj));
533534
}
534535

536+
if (prop.isAnnotationPresent(Transient.class)) {
537+
return;
538+
}
539+
535540
if (!conversions.isSimpleType(propertyObj.getClass())) {
536541
writePropertyInternal(propertyObj, target, prop, false);
537542
} else {

src/test/java/org/springframework/data/couchbase/domain/User.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.data.annotation.LastModifiedBy;
2525
import org.springframework.data.annotation.LastModifiedDate;
2626
import org.springframework.data.annotation.PersistenceConstructor;
27+
import org.springframework.data.annotation.Transient;
2728
import org.springframework.data.annotation.Version;
2829
import org.springframework.data.couchbase.core.mapping.Document;
2930

@@ -41,6 +42,8 @@ public class User extends ComparableEntity {
4142
@Id private String id;
4243
private String firstname;
4344
private String lastname;
45+
@Transient
46+
private String transientInfo;
4447
@CreatedBy private String createdBy;
4548
@CreatedDate private long createdDate;
4649
@LastModifiedBy private String lastModifiedBy;
@@ -94,4 +97,10 @@ public int hashCode() {
9497
return Objects.hash(id, firstname, lastname);
9598
}
9699

100+
public String getTransientInfo(){
101+
return transientInfo;
102+
}
103+
public void setTransientInfo(String something) {
104+
transientInfo = something;
105+
}
97106
}

src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryQueryIntegrationTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.Arrays;
3030
import java.util.List;
3131
import java.util.Locale;
32+
import java.util.Optional;
3233
import java.util.concurrent.Callable;
3334
import java.util.concurrent.ExecutorService;
3435
import java.util.concurrent.Executors;
@@ -222,6 +223,16 @@ void findByEnum() {
222223
}
223224
}
224225

226+
@Test
227+
public void testTransient() {
228+
User user = new User("1", "Dave", "Wilson");
229+
user.setTransientInfo("something");
230+
userRepository.save(user);
231+
Optional<User> foundUser = userRepository.findById(user.getId());
232+
assertEquals(null, foundUser.get().getTransientInfo());
233+
userRepository.delete(user);
234+
}
235+
225236
@Test
226237
public void testCas() {
227238
User user = new User("1", "Dave", "Wilson");

0 commit comments

Comments
 (0)