Merge pull request #239 from alex-semenyuk/master
Fixed issue with @Transient
This commit is contained in:
commit
acd6d7e18b
|
@ -1,7 +1,5 @@
|
||||||
package org.baeldung.model;
|
package org.baeldung.model;
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
|
|
||||||
import org.baeldung.annotation.CascadeSave;
|
import org.baeldung.annotation.CascadeSave;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
|
@ -80,6 +78,11 @@ public class User {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getYearOfBirth() {
|
public Integer getYearOfBirth() {
|
||||||
return Calendar.getInstance().get(Calendar.YEAR) - age;
|
return yearOfBirth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setYearOfBirth(Integer yearOfBirth) {
|
||||||
|
this.yearOfBirth = yearOfBirth;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,8 +186,9 @@ public class MongoTemplateQueryIntegrationTest {
|
||||||
public void whenSavingUser_thenYearOfBirthIsCalculated() {
|
public void whenSavingUser_thenYearOfBirthIsCalculated() {
|
||||||
final User user = new User();
|
final User user = new User();
|
||||||
user.setName("Alex");
|
user.setName("Alex");
|
||||||
|
user.setYearOfBirth(1985);
|
||||||
mongoTemplate.insert(user);
|
mongoTemplate.insert(user);
|
||||||
|
|
||||||
assertThat(mongoTemplate.findOne(Query.query(Criteria.where("name").is("Alex")), User.class).getYearOfBirth(), is(2015));
|
assertThat(user.getYearOfBirth(), is(1985));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue