1 package ch.dvbern.demo.entities;
3 import java.io.Serializable;
4 import java.util.Objects;
6 import javax.annotation.Nonnull;
7 import javax.annotation.Nullable;
8 import javax.persistence.Column;
9 import javax.persistence.Id;
10 import javax.persistence.MappedSuperclass;
11 import javax.persistence.Version;
12 import javax.validation.constraints.NotNull;
13 import javax.validation.constraints.Size;
15 import org.apache.commons.lang3.builder.ToStringBuilder;
16 import org.hibernate.Hibernate;
18 import ch.dvbern.demo.util.Constants;
20 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
22 @SuppressWarnings("ClassReferencesSubclass")
24 public abstract class AbstractEntity implements Serializable {
26 private static final long serialVersionUID = -979317154050183445L;
29 @Column(unique = true, nullable = false, updatable = false, length = Constants.UUID_LENGTH)
30 @Size(min = Constants.UUID_LENGTH, max = Constants.UUID_LENGTH)
37 @Size(max = Constants.UUID_LENGTH)
38 @Column(nullable = false, length = Constants.UUID_LENGTH)
39 private String userErstellt;
41 @Size(max = Constants.UUID_LENGTH)
42 @Column(nullable = false, length = Constants.UUID_LENGTH)
43 private String userMutiert;
45 protected AbstractEntity() {
46 //da wir teilweise schon eine id brauchen bevor die Entities gespeichert werden initialisieren wir die uuid hier
47 id = UUID.randomUUID().toString();
50 public String getId() {
54 public void setId(@Nullable String id) {
58 // Nullable, da erst im PrePersist gesetzt
59 public long getVersion() {
63 public void setVersion(long version) {
64 this.version = version;
67 @Nullable // Nullable, da erst im PrePersist gesetzt
68 public String getUserErstellt() {
72 public void setUserErstellt(@Nonnull String userErstellt) {
73 this.userErstellt = userErstellt;
76 @Nullable // Nullable, da erst im PrePersist gesetzt
77 public String getUserMutiert() {
81 public void setUserMutiert(@Nonnull String userMutiert) {
82 this.userMutiert = userMutiert;
85 @SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
86 @SuppressFBWarnings(value = "BC_EQUALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS", justification = "Es wird Hibernate.getClass genutzt um von Proxies (LazyInit) die konkrete Klasse zu erhalten")
88 public boolean equals(@Nullable Object o) {
93 if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) {
97 AbstractEntity that = (AbstractEntity) o;
99 Objects.requireNonNull(getId());
100 Objects.requireNonNull(that.getId());
102 return getId().equals(that.getId());
105 public int hashCode() {
106 return getId() != null ? getId().hashCode() : 0;
110 public String toString() {
111 return new ToStringBuilder(this)
112 .append("id", getId())