Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cb4cd3d

Browse files
author
Rajeev Kumar Singh
committed
Explicit column name
1 parent 4024533 commit cb4cd3d

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

6 files changed

+24
-8
lines changed

‎hibernate-composite-primary-key-demo/src/main/java/com/example/hibernate/model/Employee.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.example.hibernate.model;
22

3+
import org.hibernate.annotations.NaturalId;
4+
5+
import javax.persistence.Column;
36
import javax.persistence.EmbeddedId;
47
import javax.persistence.Entity;
58
import javax.persistence.Table;
@@ -21,9 +24,11 @@ public class Employee {
2124

2225
@NotNull
2326
@Size(max = 100)
27+
@NaturalId
2428
private String email;
2529

2630
@Size(max = 15)
31+
@Column(name = "phone_number", unique = true)
2732
private String phoneNumber;
2833

2934
public Employee() {

‎hibernate-many-to-many-demo/src/main/java/com/example/hibernate/model/Post.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class Post {
1919

2020
@NotNull
2121
@Size(max = 100)
22+
@Column(unique = true)
2223
private String title;
2324

2425
@NotNull
@@ -31,10 +32,12 @@ public class Post {
3132

3233
@NotNull
3334
@Temporal(TemporalType.TIMESTAMP)
35+
@Column(name = "posted_at")
3436
private Date postedAt = new Date();
3537

3638
@NotNull
3739
@Temporal(TemporalType.TIMESTAMP)
40+
@Column(name = "last_updated_at")
3841
private Date lastUpdatedAt = new Date();
3942

4043

‎hibernate-many-to-many-demo/src/main/java/com/example/hibernate/model/Tag.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.example.hibernate.model;
22

3+
import org.hibernate.annotations.NaturalId;
4+
35
import javax.persistence.*;
46
import javax.validation.constraints.NotNull;
57
import javax.validation.constraints.Size;
@@ -18,6 +20,7 @@ public class Tag {
1820

1921
@NotNull
2022
@Size(max = 100)
23+
@NaturalId
2124
private String name;
2225

2326
@ManyToMany(fetch = FetchType.LAZY,

‎hibernate-one-to-many-demo/src/main/java/com/example/hibernate/model/Post.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class Post {
1717

1818
@NotNull
1919
@Size(max = 100)
20+
@Column(unique = true)
2021
private String title;
2122

2223
@NotNull
@@ -29,10 +30,12 @@ public class Post {
2930

3031
@NotNull
3132
@Temporal(TemporalType.TIMESTAMP)
33+
@Column(name = "posted_at")
3234
private Date postedAt = new Date();
3335

3436
@NotNull
3537
@Temporal(TemporalType.TIMESTAMP)
38+
@Column(name = "last_updated_at")
3639
private Date lastUpdatedAt = new Date();
3740

3841
@OneToMany(cascade = CascadeType.ALL,

‎hibernate-one-to-one-demo/src/main/java/com/example/hibernate/model/Driver.java‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.example.hibernate.model;
22

33
import org.hibernate.validator.constraints.Email;
4-
import org.hibernate.validator.constraints.NotBlank;
54

65
import javax.persistence.*;
6+
import javax.validation.constraints.NotNull;
77
import javax.validation.constraints.Size;
88

99
/**
@@ -16,17 +16,19 @@ public class Driver {
1616
@GeneratedValue(strategy = GenerationType.AUTO)
1717
private Long id;
1818

19-
@NotBlank
19+
@NotNull
2020
@Size(max = 100)
2121
private String name;
2222

23-
@NotBlank
23+
@NotNull
2424
@Email
2525
@Size(max = 100)
26+
@Column(unique = true)
2627
private String email;
2728

28-
@NotBlank
29+
@NotNull
2930
@Size(max = 15)
31+
@Column(name = "phone_number", unique = true)
3032
private String phoneNumber;
3133

3234
@OneToOne(fetch = FetchType.LAZY,

‎hibernate-one-to-one-demo/src/main/java/com/example/hibernate/model/DrivingLicense.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.example.hibernate.model;
22

3-
import org.hibernate.validator.constraints.NotBlank;
4-
53
import javax.persistence.*;
64
import javax.validation.constraints.NotNull;
75
import java.util.Date;
@@ -16,16 +14,18 @@ public class DrivingLicense {
1614
@GeneratedValue(strategy = GenerationType.AUTO)
1715
private Long id;
1816

19-
@NotBlank
20-
@Column(unique = true)
17+
@NotNull
18+
@Column(name = "license_number", unique = true)
2119
private String licenseNumber;
2220

2321
@NotNull
2422
@Temporal(TemporalType.DATE)
23+
@Column(name = "issue_date")
2524
private Date issueDate;
2625

2726
@NotNull
2827
@Temporal(TemporalType.DATE)
28+
@Column(name = "expiry_date")
2929
private Date expiryDate;
3030

3131
@OneToOne(fetch = FetchType.LAZY)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /