2142b39679523d51b5479450cbaf9246f9afdc2f
[JavaForFun] /
1 package de.spring.example.persistence.domain;
2
3 import java.io.Serializable;
4
5 import javax.persistence.CascadeType;
6 import javax.persistence.Column;
7 import javax.persistence.Entity;
8 import javax.persistence.FetchType;
9 import javax.persistence.GeneratedValue;
10 import javax.persistence.GenerationType;
11 import javax.persistence.Id;
12 import javax.persistence.JoinColumn;
13 import javax.persistence.ManyToOne;
14 import javax.persistence.Table;
15 import javax.validation.constraints.Max;
16 import javax.validation.constraints.NotNull;
17 import javax.validation.constraints.Size;
18
19 import org.hibernate.envers.Audited;
20
21 import com.fasterxml.jackson.annotation.JsonIdentityInfo;
22 import com.fasterxml.jackson.annotation.ObjectIdGenerators;
23
24 @Entity
25 @Audited
26 @Table(name="ad_description", schema="mybatis_example")
27 @JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="jsonId")
28 public class AdDescription implements Serializable {
29
30         @Id
31         @GeneratedValue(strategy=GenerationType.IDENTITY)
32         @Column(name="id", updatable=false, nullable=false)
33         private Long id;
34         
35         @ManyToOne(fetch=FetchType.LAZY, cascade = CascadeType.ALL, optional=true)
36         @JoinColumn(name="ad_id", nullable=false, updatable = false, insertable = false, referencedColumnName="id")
37         private Ad ad;
38         
39         @NotNull
40         @Max(60)
41         @Column(name="laguage_id")
42         private Long languageId;
43         
44         @NotNull
45         @Size(min=2, max=255)
46         @Column(name="ad_name")
47         private String adName;
48
49         @NotNull
50         @Size(min=2, max=255)
51         @Column(name="ad_description")
52         private String adDescription;
53         
54         @NotNull
55         @Size(min=2, max=500)
56         @Column(name="ad_mobile_text")
57         private String adMobileText;
58         
59         @NotNull
60         @Size(min=2, max=3000)
61         @Column(name="ad_link")
62         private String adLink;
63         
64         // It will be used by JPA when filling the property fields with data coming from data base.
65         protected AdDescription() {
66
67         }
68
69         // It will be used by my code (for example by Unit Tests)
70         public AdDescription(Long id, Ad ad, Long languageId, String adName, String adDescription,
71                         String adMobileText, String adLink) {
72                 this.id = id;
73                 this.ad = ad;
74                 this.languageId = languageId;
75                 this.adName = adName;
76                 this.adDescription = adDescription;
77                 this.adMobileText = adMobileText;
78                 this.adLink = adLink;
79         }
80         
81         /**
82          * WARNING: JPA REQUIRES GETTERS!!!
83          */
84
85         public Long getId() {
86                 return id;
87         }
88
89         public Ad getAd() {
90                 return ad;
91         }
92
93         public Long getLanguageId() {
94                 return languageId;
95         }
96
97         public String getAdName() {
98                 return adName;
99         }
100
101         public String getAdDescription() {
102                 return adDescription;
103         }
104
105         public String getAdMobileText() {
106                 return adMobileText;
107         }
108
109         public String getAdLink() {
110                 return adLink;
111         }
112 }