Movatterモバイル変換


[0]ホーム

URL:


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

Commit1bc9f61

Browse files
Step 3. Modify model: extract to MappedSuperclass
1 parent6ae5d77 commit1bc9f61

File tree

3 files changed

+67
-116
lines changed

3 files changed

+67
-116
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
packageio.amplicode.blog.model;
2+
3+
importjakarta.persistence.*;
4+
5+
importjava.time.Instant;
6+
7+
@MappedSuperclass
8+
publicclassBaseEntity {
9+
@Id
10+
@GeneratedValue(strategy =GenerationType.IDENTITY)
11+
@Column(name ="id",nullable =false)
12+
privateLongid;
13+
14+
@Column(name ="created_by")
15+
privateStringcreatedBy;
16+
17+
@Column(name ="created_date")
18+
privateInstantcreatedDate;
19+
20+
@Column(name ="last_modified_by")
21+
privateStringlastModifiedBy;
22+
23+
@Column(name ="last_modified_date")
24+
privateInstantlastModifiedDate;
25+
26+
publicLonggetId() {
27+
returnid;
28+
}
29+
30+
publicvoidsetId(Longid) {
31+
this.id =id;
32+
}
33+
34+
publicStringgetCreatedBy() {
35+
returncreatedBy;
36+
}
37+
38+
publicvoidsetCreatedBy(StringcreatedBy) {
39+
this.createdBy =createdBy;
40+
}
41+
42+
publicInstantgetCreatedDate() {
43+
returncreatedDate;
44+
}
45+
46+
publicvoidsetCreatedDate(InstantcreatedDate) {
47+
this.createdDate =createdDate;
48+
}
49+
50+
publicStringgetLastModifiedBy() {
51+
returnlastModifiedBy;
52+
}
53+
54+
publicvoidsetLastModifiedBy(StringlastModifiedBy) {
55+
this.lastModifiedBy =lastModifiedBy;
56+
}
57+
58+
publicInstantgetLastModifiedDate() {
59+
returnlastModifiedDate;
60+
}
61+
62+
publicvoidsetLastModifiedDate(InstantlastModifiedDate) {
63+
this.lastModifiedDate =lastModifiedDate;
64+
}
65+
}

‎generate-entities-from-db/blog/src/main/java/io/amplicode/blog/model/Post.java‎

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,7 @@
66

77
@Entity
88
@Table(name ="posts")
9-
publicclassPost {
10-
@Id
11-
@GeneratedValue(strategy =GenerationType.IDENTITY)
12-
@Column(name ="id",nullable =false)
13-
privateLongid;
14-
15-
@Column(name ="created_by")
16-
privateStringcreatedBy;
17-
18-
@Column(name ="created_date")
19-
privateInstantcreatedDate;
20-
21-
@Column(name ="last_modified_by")
22-
privateStringlastModifiedBy;
23-
24-
@Column(name ="last_modified_date")
25-
privateInstantlastModifiedDate;
26-
9+
publicclassPostextendsBaseEntity {
2710
@Column(name ="title",nullable =false)
2811
privateStringtitle;
2912

@@ -38,46 +21,6 @@ public class Post {
3821
@JoinColumn(name ="author_id",nullable =false)
3922
privateUserauthor;
4023

41-
publicLonggetId() {
42-
returnid;
43-
}
44-
45-
publicvoidsetId(Longid) {
46-
this.id =id;
47-
}
48-
49-
publicStringgetCreatedBy() {
50-
returncreatedBy;
51-
}
52-
53-
publicvoidsetCreatedBy(StringcreatedBy) {
54-
this.createdBy =createdBy;
55-
}
56-
57-
publicInstantgetCreatedDate() {
58-
returncreatedDate;
59-
}
60-
61-
publicvoidsetCreatedDate(InstantcreatedDate) {
62-
this.createdDate =createdDate;
63-
}
64-
65-
publicStringgetLastModifiedBy() {
66-
returnlastModifiedBy;
67-
}
68-
69-
publicvoidsetLastModifiedBy(StringlastModifiedBy) {
70-
this.lastModifiedBy =lastModifiedBy;
71-
}
72-
73-
publicInstantgetLastModifiedDate() {
74-
returnlastModifiedDate;
75-
}
76-
77-
publicvoidsetLastModifiedDate(InstantlastModifiedDate) {
78-
this.lastModifiedDate =lastModifiedDate;
79-
}
80-
8124
publicStringgetTitle() {
8225
returntitle;
8326
}

‎generate-entities-from-db/blog/src/main/java/io/amplicode/blog/model/User.java‎

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,7 @@
1010
@Table(name ="users",indexes = {
1111
@Index(name ="idx_user_names",columnList ="first_name, last_name")
1212
})
13-
publicclassUser {
14-
@Id
15-
@GeneratedValue(strategy =GenerationType.IDENTITY)
16-
@Column(name ="id",nullable =false)
17-
privateLongid;
18-
19-
@Column(name ="created_by")
20-
privateStringcreatedBy;
21-
22-
@Column(name ="created_date")
23-
privateInstantcreatedDate;
24-
25-
@Column(name ="last_modified_by")
26-
privateStringlastModifiedBy;
27-
28-
@Column(name ="last_modified_date")
29-
privateInstantlastModifiedDate;
30-
13+
publicclassUserextendsBaseEntity {
3114
@Column(name ="first_name",nullable =false)
3215
privateStringfirstName;
3316

@@ -37,46 +20,6 @@ public class User {
3720
@OneToMany(mappedBy ="author")
3821
privateSet<Post>posts =newLinkedHashSet<>();
3922

40-
publicLonggetId() {
41-
returnid;
42-
}
43-
44-
publicvoidsetId(Longid) {
45-
this.id =id;
46-
}
47-
48-
publicStringgetCreatedBy() {
49-
returncreatedBy;
50-
}
51-
52-
publicvoidsetCreatedBy(StringcreatedBy) {
53-
this.createdBy =createdBy;
54-
}
55-
56-
publicInstantgetCreatedDate() {
57-
returncreatedDate;
58-
}
59-
60-
publicvoidsetCreatedDate(InstantcreatedDate) {
61-
this.createdDate =createdDate;
62-
}
63-
64-
publicStringgetLastModifiedBy() {
65-
returnlastModifiedBy;
66-
}
67-
68-
publicvoidsetLastModifiedBy(StringlastModifiedBy) {
69-
this.lastModifiedBy =lastModifiedBy;
70-
}
71-
72-
publicInstantgetLastModifiedDate() {
73-
returnlastModifiedDate;
74-
}
75-
76-
publicvoidsetLastModifiedDate(InstantlastModifiedDate) {
77-
this.lastModifiedDate =lastModifiedDate;
78-
}
79-
8023
publicStringgetFirstName() {
8124
returnfirstName;
8225
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp