mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 20:25:50 +00:00
Fix #111 For pet's birthday we are now using jodatime LocalDate instead of DateTime
This commit is contained in:
parent
4aa89ae4e2
commit
92de6557e1
3 changed files with 9 additions and 6 deletions
|
@ -32,6 +32,7 @@ import javax.persistence.Table;
|
|||
|
||||
import org.hibernate.annotations.Type;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.springframework.beans.support.MutableSortDefinition;
|
||||
import org.springframework.beans.support.PropertyComparator;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
@ -48,9 +49,9 @@ import org.springframework.format.annotation.DateTimeFormat;
|
|||
public class Pet extends NamedEntity {
|
||||
|
||||
@Column(name = "birth_date")
|
||||
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
|
||||
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
|
||||
@DateTimeFormat(pattern = "yyyy/MM/dd")
|
||||
private DateTime birthDate;
|
||||
private LocalDate birthDate;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "type_id")
|
||||
|
@ -63,11 +64,11 @@ public class Pet extends NamedEntity {
|
|||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "pet", fetch = FetchType.EAGER)
|
||||
private Set<Visit> visits;
|
||||
|
||||
public DateTime getBirthDate() {
|
||||
public LocalDate getBirthDate() {
|
||||
return this.birthDate;
|
||||
}
|
||||
|
||||
public void setBirthDate(DateTime birthDate) {
|
||||
public void setBirthDate(LocalDate birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.sql.SQLException;
|
|||
import java.util.Date;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
/**
|
||||
|
@ -34,7 +35,7 @@ class JdbcPetRowMapper implements RowMapper<JdbcPet> {
|
|||
pet.setId(rs.getInt("pets.id"));
|
||||
pet.setName(rs.getString("name"));
|
||||
Date birthDate = rs.getDate("birth_date");
|
||||
pet.setBirthDate(new DateTime(birthDate));
|
||||
pet.setBirthDate(new LocalDate(birthDate));
|
||||
pet.setTypeId(rs.getInt("type_id"));
|
||||
pet.setOwnerId(rs.getInt("owner_id"));
|
||||
return pet;
|
||||
|
|
|
@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
import java.util.Collection;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.samples.petclinic.model.Owner;
|
||||
|
@ -135,7 +136,7 @@ public abstract class AbstractClinicServiceTests {
|
|||
pet.setName("bowser");
|
||||
Collection<PetType> types = this.clinicService.findPetTypes();
|
||||
pet.setType(EntityUtils.getById(types, PetType.class, 2));
|
||||
pet.setBirthDate(new DateTime());
|
||||
pet.setBirthDate(new LocalDate());
|
||||
owner6.addPet(pet);
|
||||
assertThat(owner6.getPets().size()).isEqualTo(found + 1);
|
||||
|
||||
|
|
Loading…
Reference in a new issue