Fixed issue with @Transient

This commit is contained in:
alex-semenyuk 2015-08-22 08:43:06 +02:00
parent a690614d49
commit 11c364d9cf
2 changed files with 8 additions and 4 deletions

View File

@ -1,7 +1,5 @@
package org.baeldung.model;
import java.util.Calendar;
import org.baeldung.annotation.CascadeSave;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.annotation.Id;
@ -80,6 +78,11 @@ public class User {
}
public Integer getYearOfBirth() {
return Calendar.getInstance().get(Calendar.YEAR) - age;
return yearOfBirth;
}
public void setYearOfBirth(Integer yearOfBirth) {
this.yearOfBirth = yearOfBirth;
}
}

View File

@ -186,8 +186,9 @@ public class MongoTemplateQueryIntegrationTest {
public void whenSavingUser_thenYearOfBirthIsCalculated() {
final User user = new User();
user.setName("Alex");
user.setYearOfBirth(1985);
mongoTemplate.insert(user);
assertThat(mongoTemplate.findOne(Query.query(Criteria.where("name").is("Alex")), User.class).getYearOfBirth(), is(2015));
assertThat(user.getYearOfBirth(), is(1985));
}
}