diff --git a/src/main/java/fr/eni/demo/bo/Client.java b/src/main/java/fr/eni/demo/bo/Client.java index e49b930..cc7e863 100644 --- a/src/main/java/fr/eni/demo/bo/Client.java +++ b/src/main/java/fr/eni/demo/bo/Client.java @@ -27,7 +27,7 @@ public class Client { @Column(nullable = false, unique = true) private String email; - @OneToOne + @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER, optional = false) @JoinColumn(name = "LOCATION_ID") private Location location; } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 39fdf67..a63d823 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -3,9 +3,9 @@ spring: name: demo1 #Connection to DB datasource: - url: jdbc:sqlserver://localhost;databasename=ludotheque;integratedSecurity=false;encrypt=false;trustServerCertificate=false - username: sa - password: Pa$$w0rd + url: jdbc:sqlserver://localhost;databasename=LUDO_DB;integratedSecurity=false;encrypt=false;trustServerCertificate=false + username: LUDO_USER + password: LUDO_PWD #Options to DB jpa: diff --git a/src/test/java/fr/eni/demo/DemoApplicationTests.java b/src/test/java/fr/eni/demo/DemoApplicationTests.java index 6a3550c..0f837b8 100644 --- a/src/test/java/fr/eni/demo/DemoApplicationTests.java +++ b/src/test/java/fr/eni/demo/DemoApplicationTests.java @@ -28,30 +28,32 @@ class DemoApplicationTests { @Autowired private StockService stockService; - @Test - @DisplayName("-- Test add Client --") - void testAddClient() { - //Création de l'objet client - Client client = new Client(); - client.setEmail("olivier@test.fr"); - client.setNom("Parpaillon"); - client.setPrenom("Olivier"); - - clientService.add(client); - System.out.println(client); - } - - @Test - @DisplayName("-- Test add Location --") - void testAddLocation() { - Location location = new Location(); - location.setRue("18 Rue de la Paix"); - location.setCodePostal("75000"); - location.setVille("Paris"); - - locationService.add(location); - System.out.println(location); - } +// DEPREACTED CAUSE : Cant add Client without Location +// @Test +// @DisplayName("-- Test add Client --") +// void testAddClient() { +// Client client = new Client(); +// client.setEmail("olivier@test.fr"); +// client.setNom("Parpaillon"); +// client.setPrenom("Olivier"); +// +// clientService.add(client); +// System.out.println(client); +// } +// +// DEPRECATED CAUSE : Orphan removal on Client.Location, +// so if you add Location without Client, it will be deleted by the ORM +// @Test +// @DisplayName("-- Test add Location --") +// void testAddLocation() { +// Location location = new Location(); +// location.setRue("18 Rue de la Paix"); +// location.setCodePostal("75000"); +// location.setVille("Paris"); +// +// locationService.add(location); +// System.out.println(location); +// } @Test @DisplayName("-- Test add Client with Location --") @@ -67,7 +69,6 @@ class DemoApplicationTests { location.setRue("666 Rue des Enfers"); location.setCodePostal("44000"); location.setVille("Nantes"); - locationService.add(location); //Ajout de la location au client client.setLocation(location); @@ -110,12 +111,10 @@ class DemoApplicationTests { // Création des genres de jeu GameType gameTypeFPS = new GameType(); gameTypeFPS.setName("FPS"); -// gameTypeService.add(gameTypeFPS); System.out.println(gameTypeFPS); GameType gameTypeOnline = new GameType(); gameTypeOnline.setName("Multijoueur"); -// gameTypeService.add(gameTypeOnline); System.out.println(gameTypeOnline); List gameTypes = new ArrayList<>();