Skip to content

Commit 55e09af

Browse files
author
dupirefr
committed
[BAEL-2048] Spring Data JPA multiple databases article
1 parent 8aa7dc5 commit 55e09af

12 files changed

Lines changed: 181 additions & 26 deletions

File tree

‎persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/multiple/model/user/Possession.java‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package org.baeldung.persistence.multiple.model.user;
22

3-
import javax.persistence.Entity;
4-
import javax.persistence.GeneratedValue;
5-
import javax.persistence.GenerationType;
6-
import javax.persistence.Id;
7-
import javax.persistence.Table;
3+
import javax.persistence.*;
84

95
@Entity
106
@Table(schema = "spring_jpa_user")

‎persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/multiple/model/user/User.java‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
package org.baeldung.persistence.multiple.model.user;
22

3+
import javax.persistence.*;
34
import java.util.List;
45

5-
import javax.persistence.Column;
6-
import javax.persistence.Entity;
7-
import javax.persistence.GeneratedValue;
8-
import javax.persistence.GenerationType;
9-
import javax.persistence.Id;
10-
import javax.persistence.OneToMany;
11-
import javax.persistence.Table;
12-
136
@Entity
147
@Table(schema = "spring_jpa_user")
158
public class User {

persistence-modules/spring-jpa/src/main/java/org/baeldung/config/ProductConfig.java renamed to spring-data-jpa/src/main/java/org/baeldung/config/ProductConfig.java

File renamed without changes.

persistence-modules/spring-jpa/src/main/java/org/baeldung/config/UserConfig.java renamed to spring-data-jpa/src/main/java/org/baeldung/config/UserConfig.java

File renamed without changes.

persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/multiple/dao/product/ProductRepository.java renamed to spring-data-jpa/src/main/java/org/baeldung/persistence/multiple/dao/product/ProductRepository.java

File renamed without changes.

persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/multiple/dao/user/PossessionRepository.java renamed to spring-data-jpa/src/main/java/org/baeldung/persistence/multiple/dao/user/PossessionRepository.java

File renamed without changes.

persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/multiple/dao/user/UserRepository.java renamed to spring-data-jpa/src/main/java/org/baeldung/persistence/multiple/dao/user/UserRepository.java

File renamed without changes.

persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/multiple/model/product/Product.java renamed to spring-data-jpa/src/main/java/org/baeldung/persistence/multiple/model/product/Product.java

File renamed without changes.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package org.baeldung.persistence.multiple.model.user;
2+
3+
import javax.persistence.Entity;
4+
import javax.persistence.GeneratedValue;
5+
import javax.persistence.GenerationType;
6+
import javax.persistence.Id;
7+
import javax.persistence.Table;
8+
9+
@Entity
10+
@Table(schema = "spring_jpa_user")
11+
public class Possession {
12+
13+
@Id
14+
@GeneratedValue(strategy = GenerationType.IDENTITY)
15+
private long id;
16+
17+
private String name;
18+
19+
public Possession() {
20+
super();
21+
}
22+
23+
public Possession(final String name) {
24+
super();
25+
26+
this.name = name;
27+
}
28+
29+
public long getId() {
30+
return id;
31+
}
32+
33+
public void setId(final int id) {
34+
this.id = id;
35+
}
36+
37+
public String getName() {
38+
return name;
39+
}
40+
41+
public void setName(final String name) {
42+
this.name = name;
43+
}
44+
45+
@Override
46+
public int hashCode() {
47+
final int prime = 31;
48+
int result = 1;
49+
result = (prime * result) + (int) (id ^ (id >>> 32));
50+
result = (prime * result) + ((name == null) ? 0 : name.hashCode());
51+
return result;
52+
}
53+
54+
@Override
55+
public boolean equals(Object obj) {
56+
if (this == obj) {
57+
return true;
58+
}
59+
if (obj == null) {
60+
return false;
61+
}
62+
if (getClass() != obj.getClass()) {
63+
return false;
64+
}
65+
final Possession other = (Possession) obj;
66+
if (id != other.id) {
67+
return false;
68+
}
69+
if (name == null) {
70+
if (other.name != null) {
71+
return false;
72+
}
73+
} else if (!name.equals(other.name)) {
74+
return false;
75+
}
76+
return true;
77+
}
78+
79+
@Override
80+
public String toString() {
81+
final StringBuilder builder = new StringBuilder();
82+
builder.append("Possesion [id=").append(id).append(", name=").append(name).append("]");
83+
return builder.toString();
84+
}
85+
86+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package org.baeldung.persistence.multiple.model.user;
2+
3+
import java.util.List;
4+
5+
import javax.persistence.Column;
6+
import javax.persistence.Entity;
7+
import javax.persistence.GeneratedValue;
8+
import javax.persistence.GenerationType;
9+
import javax.persistence.Id;
10+
import javax.persistence.OneToMany;
11+
import javax.persistence.Table;
12+
13+
@Entity
14+
@Table(schema = "spring_jpa_user")
15+
public class User {
16+
17+
@Id
18+
@GeneratedValue(strategy = GenerationType.IDENTITY)
19+
private int id;
20+
21+
private String name;
22+
23+
@Column(unique = true, nullable = false)
24+
private String email;
25+
26+
private int age;
27+
28+
@OneToMany
29+
List<Possession> possessionList;
30+
31+
public User() {
32+
super();
33+
}
34+
35+
public int getId() {
36+
return id;
37+
}
38+
39+
public void setId(final int id) {
40+
this.id = id;
41+
}
42+
43+
public String getName() {
44+
return name;
45+
}
46+
47+
public void setName(final String name) {
48+
this.name = name;
49+
}
50+
51+
public String getEmail() {
52+
return email;
53+
}
54+
55+
public void setEmail(final String email) {
56+
this.email = email;
57+
}
58+
59+
public int getAge() {
60+
return age;
61+
}
62+
63+
public void setAge(final int age) {
64+
this.age = age;
65+
}
66+
67+
public List<Possession> getPossessionList() {
68+
return possessionList;
69+
}
70+
71+
public void setPossessionList(List<Possession> possessionList) {
72+
this.possessionList = possessionList;
73+
}
74+
75+
@Override
76+
public String toString() {
77+
final StringBuilder builder = new StringBuilder();
78+
builder.append("User [name=").append(name).append(", id=").append(id).append("]");
79+
return builder.toString();
80+
}
81+
}

0 commit comments

Comments
 (0)