forked from Realhedin/topjava02
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseEntity.java
More file actions
65 lines (53 loc) · 1.72 KB
/
BaseEntity.java
File metadata and controls
65 lines (53 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package ru.javawebinar.topjava.model;
import ru.javawebinar.topjava.LoggerWrapper;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.SequenceGenerator;
import java.io.Serializable;
/**
* User: gkislin
* Date: 22.08.2014
*/
@MappedSuperclass
@Access(AccessType.FIELD)
//@JsonAutoDetect(fieldVisibility = ANY, getterVisibility = NONE, isGetterVisibility = NONE, setterVisibility = NONE)
public class BaseEntity implements Serializable{
protected static final LoggerWrapper LOG = LoggerWrapper.get(BaseEntity.class);
public static final int START_SEQ = 100000;
@Id
@SequenceGenerator(name = "global_seq", sequenceName = "global_seq", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "global_seq")
protected Integer id;
public BaseEntity() {
}
protected BaseEntity(Integer id) {
this.id = id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public boolean isNew() {
return (this.id == null);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BaseEntity that = (BaseEntity) o;
if (id == null || that.id == null) {
throw LOG.getIllegalStateException("Equals '" + this + "' and '" + that + "' with null id");
}
return id.equals(that.id);
}
@Override
public int hashCode() {
return (id == null) ? 0 : id;
}
}