File tree Expand file tree Collapse file tree 6 files changed +24
-8
lines changed
hibernate-composite-primary-key-demo/src/main/java/com/example/hibernate/model
hibernate-many-to-many-demo/src/main/java/com/example/hibernate/model
hibernate-one-to-many-demo/src/main/java/com/example/hibernate/model
hibernate-one-to-one-demo/src/main/java/com/example/hibernate/model Expand file tree Collapse file tree 6 files changed +24
-8
lines changed Original file line number Diff line number Diff line change 1
1
package com .example .hibernate .model ;
2
2
3
+ import org .hibernate .annotations .NaturalId ;
4
+
5
+ import javax .persistence .Column ;
3
6
import javax .persistence .EmbeddedId ;
4
7
import javax .persistence .Entity ;
5
8
import javax .persistence .Table ;
@@ -21,9 +24,11 @@ public class Employee {
21
24
22
25
@ NotNull
23
26
@ Size (max = 100 )
27
+ @ NaturalId
24
28
private String email ;
25
29
26
30
@ Size (max = 15 )
31
+ @ Column (name = "phone_number" , unique = true )
27
32
private String phoneNumber ;
28
33
29
34
public Employee () {
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ public class Post {
19
19
20
20
@ NotNull
21
21
@ Size (max = 100 )
22
+ @ Column (unique = true )
22
23
private String title ;
23
24
24
25
@ NotNull
@@ -31,10 +32,12 @@ public class Post {
31
32
32
33
@ NotNull
33
34
@ Temporal (TemporalType .TIMESTAMP )
35
+ @ Column (name = "posted_at" )
34
36
private Date postedAt = new Date ();
35
37
36
38
@ NotNull
37
39
@ Temporal (TemporalType .TIMESTAMP )
40
+ @ Column (name = "last_updated_at" )
38
41
private Date lastUpdatedAt = new Date ();
39
42
40
43
Original file line number Diff line number Diff line change 1
1
package com .example .hibernate .model ;
2
2
3
+ import org .hibernate .annotations .NaturalId ;
4
+
3
5
import javax .persistence .*;
4
6
import javax .validation .constraints .NotNull ;
5
7
import javax .validation .constraints .Size ;
@@ -18,6 +20,7 @@ public class Tag {
18
20
19
21
@ NotNull
20
22
@ Size (max = 100 )
23
+ @ NaturalId
21
24
private String name ;
22
25
23
26
@ ManyToMany (fetch = FetchType .LAZY ,
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ public class Post {
17
17
18
18
@ NotNull
19
19
@ Size (max = 100 )
20
+ @ Column (unique = true )
20
21
private String title ;
21
22
22
23
@ NotNull
@@ -29,10 +30,12 @@ public class Post {
29
30
30
31
@ NotNull
31
32
@ Temporal (TemporalType .TIMESTAMP )
33
+ @ Column (name = "posted_at" )
32
34
private Date postedAt = new Date ();
33
35
34
36
@ NotNull
35
37
@ Temporal (TemporalType .TIMESTAMP )
38
+ @ Column (name = "last_updated_at" )
36
39
private Date lastUpdatedAt = new Date ();
37
40
38
41
@ OneToMany (cascade = CascadeType .ALL ,
Original file line number Diff line number Diff line change 1
1
package com .example .hibernate .model ;
2
2
3
3
import org .hibernate .validator .constraints .Email ;
4
- import org .hibernate .validator .constraints .NotBlank ;
5
4
6
5
import javax .persistence .*;
6
+ import javax .validation .constraints .NotNull ;
7
7
import javax .validation .constraints .Size ;
8
8
9
9
/**
@@ -16,17 +16,19 @@ public class Driver {
16
16
@ GeneratedValue (strategy = GenerationType .AUTO )
17
17
private Long id ;
18
18
19
- @ NotBlank
19
+ @ NotNull
20
20
@ Size (max = 100 )
21
21
private String name ;
22
22
23
- @ NotBlank
23
+ @ NotNull
24
24
@ Email
25
25
@ Size (max = 100 )
26
+ @ Column (unique = true )
26
27
private String email ;
27
28
28
- @ NotBlank
29
+ @ NotNull
29
30
@ Size (max = 15 )
31
+ @ Column (name = "phone_number" , unique = true )
30
32
private String phoneNumber ;
31
33
32
34
@ OneToOne (fetch = FetchType .LAZY ,
Original file line number Diff line number Diff line change 1
1
package com .example .hibernate .model ;
2
2
3
- import org .hibernate .validator .constraints .NotBlank ;
4
-
5
3
import javax .persistence .*;
6
4
import javax .validation .constraints .NotNull ;
7
5
import java .util .Date ;
@@ -16,16 +14,18 @@ public class DrivingLicense {
16
14
@ GeneratedValue (strategy = GenerationType .AUTO )
17
15
private Long id ;
18
16
19
- @ NotBlank
20
- @ Column (unique = true )
17
+ @ NotNull
18
+ @ Column (name = "license_number" , unique = true )
21
19
private String licenseNumber ;
22
20
23
21
@ NotNull
24
22
@ Temporal (TemporalType .DATE )
23
+ @ Column (name = "issue_date" )
25
24
private Date issueDate ;
26
25
27
26
@ NotNull
28
27
@ Temporal (TemporalType .DATE )
28
+ @ Column (name = "expiry_date" )
29
29
private Date expiryDate ;
30
30
31
31
@ OneToOne (fetch = FetchType .LAZY )
You can’t perform that action at this time.
0 commit comments