From 801b15d9ccfea3ec55d9668947c6efd904569604 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Fri, 1 Jul 2016 03:00:19 +0200 Subject: [PATCH] JPA + Spring + REST --- .../de/spring/persistence/example/domain/Ad.java | 98 +++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/SpringJava/JPA/src/main/java/de/spring/persistence/example/domain/Ad.java b/SpringJava/JPA/src/main/java/de/spring/persistence/example/domain/Ad.java index cc9fd31..e29ec68 100644 --- a/SpringJava/JPA/src/main/java/de/spring/persistence/example/domain/Ad.java +++ b/SpringJava/JPA/src/main/java/de/spring/persistence/example/domain/Ad.java @@ -9,6 +9,9 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; +import javax.validation.constraints.Max; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; @Entity @Table(schema = "mybatis_example") @@ -19,17 +22,110 @@ public class Ad implements Serializable { @Column(name = "id", updatable = false, nullable = false) private Long id; + @Max(60) private Long companyId; + @Max(40) @Column private Long companyCategId; + @Size(min=2, max=240) @Column private String adMobileImage; - + + @NotNull @Column(nullable = false) private LocalDateTime createdAt; + @NotNull @Column(nullable = false) private LocalDateTime updatedAt; + + // It will be used by JPA when filling the property fields with data coming from data base. + protected Ad() { + + } + + // It will be used by my code (for example by Unit Tests) + public Ad(Long id, Long companyId, Long companyCategId, String adMobileImage, LocalDateTime createdAt, + LocalDateTime updatedAt) { + this.id = id; + this.companyCategId = companyCategId; + this.adMobileImage = adMobileImage; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } + + public Long getId() { + return id; + } + + public Long getCompanyId() { + return companyId; + } + + public Long getCompanyCategId() { + return companyCategId; + } + + public String getAdMobileImage() { + return adMobileImage; + } + + public LocalDateTime getCreatedAt() { + return createdAt; + } + + public LocalDateTime getUpdatedAt() { + return updatedAt; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((adMobileImage == null) ? 0 : adMobileImage.hashCode()); + result = prime * result + ((companyCategId == null) ? 0 : companyCategId.hashCode()); + result = prime * result + ((companyId == null) ? 0 : companyId.hashCode()); + result = prime * result + ((createdAt == null) ? 0 : createdAt.hashCode()); + result = prime * result + ((updatedAt == null) ? 0 : updatedAt.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Ad other = (Ad) obj; + if (adMobileImage == null) { + if (other.adMobileImage != null) + return false; + } else if (!adMobileImage.equals(other.adMobileImage)) + return false; + if (companyCategId == null) { + if (other.companyCategId != null) + return false; + } else if (!companyCategId.equals(other.companyCategId)) + return false; + if (companyId == null) { + if (other.companyId != null) + return false; + } else if (!companyId.equals(other.companyId)) + return false; + if (createdAt == null) { + if (other.createdAt != null) + return false; + } else if (!createdAt.equals(other.createdAt)) + return false; + if (updatedAt == null) { + if (other.updatedAt != null) + return false; + } else if (!updatedAt.equals(other.updatedAt)) + return false; + return true; + } } -- 2.1.4