BAEL-3712: Fix entities names (#10028)

This commit is contained in:
kwoyke 2020-09-14 11:24:29 +02:00 committed by GitHub
parent 89f0f75667
commit bd9ac72a7c
5 changed files with 21 additions and 21 deletions

View File

@ -2,8 +2,8 @@ package com.baeldung.multipledb.dao.user;
import org.springframework.data.jpa.repository.JpaRepository;
import com.baeldung.multipledb.model.user.PossessionMultipleDB;
import com.baeldung.multipledb.model.user.Possession;
public interface PossessionRepository extends JpaRepository<PossessionMultipleDB, Long> {
public interface PossessionRepository extends JpaRepository<Possession, Long> {
}

View File

@ -2,7 +2,7 @@ package com.baeldung.multipledb.dao.user;
import org.springframework.data.jpa.repository.JpaRepository;
import com.baeldung.multipledb.model.user.UserMultipleDB;
import com.baeldung.multipledb.model.user.User;
public interface UserRepository extends JpaRepository<UserMultipleDB, Integer> {
public interface UserRepository extends JpaRepository<User, Integer> {
}

View File

@ -4,7 +4,7 @@ import javax.persistence.*;
@Entity
@Table
public class PossessionMultipleDB {
public class Possession {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ -12,11 +12,11 @@ public class PossessionMultipleDB {
private String name;
public PossessionMultipleDB() {
public Possession() {
super();
}
public PossessionMultipleDB(final String name) {
public Possession(final String name) {
super();
this.name = name;
@ -58,7 +58,7 @@ public class PossessionMultipleDB {
if (getClass() != obj.getClass()) {
return false;
}
final PossessionMultipleDB other = (PossessionMultipleDB) obj;
final Possession other = (Possession) obj;
if (id != other.id) {
return false;
}

View File

@ -6,7 +6,7 @@ import java.util.List;
@Entity
@Table(name = "users")
public class UserMultipleDB {
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ -18,13 +18,13 @@ public class UserMultipleDB {
private Integer status;
@OneToMany
List<PossessionMultipleDB> possessionList;
List<Possession> possessionList;
public UserMultipleDB() {
public User() {
super();
}
public UserMultipleDB(String name, String email, Integer status) {
public User(String name, String email, Integer status) {
this.name = name;
this.email = email;
this.status = status;
@ -70,11 +70,11 @@ public class UserMultipleDB {
this.age = age;
}
public List<PossessionMultipleDB> getPossessionList() {
public List<Possession> getPossessionList() {
return possessionList;
}
public void setPossessionList(List<PossessionMultipleDB> possessionList) {
public void setPossessionList(List<Possession> possessionList) {
this.possessionList = possessionList;
}

View File

@ -20,8 +20,8 @@ import com.baeldung.multipledb.dao.product.ProductRepository;
import com.baeldung.multipledb.dao.user.PossessionRepository;
import com.baeldung.multipledb.dao.user.UserRepository;
import com.baeldung.multipledb.model.product.Product;
import com.baeldung.multipledb.model.user.PossessionMultipleDB;
import com.baeldung.multipledb.model.user.UserMultipleDB;
import com.baeldung.multipledb.model.user.Possession;
import com.baeldung.multipledb.model.user.User;
@RunWith(SpringRunner.class)
@SpringBootTest(classes=MultipleDbApplication.class)
@ -42,15 +42,15 @@ public class JpaMultipleDBIntegrationTest {
@Test
@Transactional("userTransactionManager")
public void whenCreatingUser_thenCreated() {
UserMultipleDB user = new UserMultipleDB();
User user = new User();
user.setName("John");
user.setEmail("john@test.com");
user.setAge(20);
PossessionMultipleDB p = new PossessionMultipleDB("sample");
Possession p = new Possession("sample");
p = possessionRepository.save(p);
user.setPossessionList(Collections.singletonList(p));
user = userRepository.save(user);
final Optional<UserMultipleDB> result = userRepository.findById(user.getId());
final Optional<User> result = userRepository.findById(user.getId());
assertTrue(result.isPresent());
System.out.println(result.get().getPossessionList());
assertEquals(1, result.get().getPossessionList().size());
@ -59,14 +59,14 @@ public class JpaMultipleDBIntegrationTest {
@Test
@Transactional("userTransactionManager")
public void whenCreatingUsersWithSameEmail_thenRollback() {
UserMultipleDB user1 = new UserMultipleDB();
User user1 = new User();
user1.setName("John");
user1.setEmail("john@test.com");
user1.setAge(20);
user1 = userRepository.save(user1);
assertTrue(userRepository.findById(user1.getId()).isPresent());
UserMultipleDB user2 = new UserMultipleDB();
User user2 = new User();
user2.setName("Tom");
user2.setEmail("john@test.com");
user2.setAge(10);