Merge pull request #239 from alex-semenyuk/master

Fixed issue with @Transient
This commit is contained in:
Eugen 2015-08-22 02:35:30 -07:00
commit acd6d7e18b
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));
}
}