Bonjour,

Je suis débutant avec Spring Boot. J'ai suivi le tutoriel suivant à la (quasi) lettre : http://sqli.developpez.com/tutoriels...nd-springboot/

Avec néanmoins les différences suivantes :
- Ma base de données est déjà créée
- J'utilise un fichier application.properties au lieu de application.yml
- spring.jpa.hibernate.ddl-auto = validate

Je souhaite juste récupérer tous les utilisateurs via un service getAllUtilisateur() dans un @RestController.

Code application.properties : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Datasource settings
spring.datasource.url = jdbc:postgresql://131.137.126.118:5437/DIPP
spring.datasource.username = postgres
spring.datasource.password = postgres
spring.datasource.driver-class-name = org.postgresql.Driver
 
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
 
# Show or not log for each sql query
spring.jpa.show-sql = true
 
# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto = validate
 
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.EJB3NamingStrategy
 
#spring.jpa.hibernate.defaut-schema = DIPP
 
# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager)
 
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect

Code Utilisateur.java : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
@Entity
@Table(name = "utilisateurs")
public class Utilisateur {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;
 
	private String code;
 
	private String prenom;
 
	private String nom;
 
	private String email;
 
	private String langue;
 
	public Integer getId() {
		return id;
	}
 
	public void setId(Integer id) {
		this.id = id;
	}
 
	public String getCode() {
		return code;
	}
 
	public void setCode(String code) {
		this.code = code;
	}
 
	public String getPrenom() {
		return prenom;
	}
 
	public void setPrenom(String prenom) {
		this.prenom = prenom;
	}
 
	public String getNom() {
		return nom;
	}
 
	public void setNom(String nom) {
		this.nom = nom;
	}
 
	public String getEmail() {
		return email;
	}
 
	public void setEmail(String email) {
		this.email = email;
	}
 
	public String getLangue() {
		return langue;
	}
 
	public void setLangue(String langue) {
		this.langue = langue;
	}
}

Code MainApplication.java : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package com.elis;
 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
 
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class MainApplication {
	public static void main(String[] args) throws Exception {
		SpringApplication.run(MainApplication.class, args);
	}
}

Code pom.xml : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.elis</groupId>
	<artifactId>dipp</artifactId>
	<version>0.0.1-SNAPSHOT</version>
 
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.3.5.RELEASE</version>
	</parent>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
		</dependency>
		<dependency>
			<groupId>org.postgresql</groupId>
			<artifactId>postgresql</artifactId>
			<version>9.4.1208.jre7</version>
		</dependency>
	</dependencies>
 
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

Lorsque je démarre mon application, il n'y a aucune erreur. Mon entité est bien validée. Si je m'amuse à rajouter à mon entité des attributs qui n'existent pas en base, hibernate va me crier dessus.

Maintenant, lorsque j'appelle mon service http://localhost:8080/users, j'ai une erreur qui apparaît dans la console d'Eclipse :
org.postgresql.util.PSQLException: ERREUR: la relation « utilisateurs » n'existe pas

Voici la requête générée par Hibernate :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
Hibernate: select utilisateu0_.id as id1_0_, utilisateu0_.code as code2_0_, utilisateu0_.email as email3_0_, utilisateu0_.langue as langue4_0_, utilisateu0_.nom as nom5_0_, utilisateu0_.prenom as prenom6_0_ from utilisateurs utilisateu0_
(note : j'ai fait attention au nommage, pas de guillemet lors de la création des tables)

Lorsque je la copie/colle dans SQL Developer, elle passe !

Donc que se passe-t-il avec mon application ? Pourquoi ne trouve-t-il pas la table ?

Merci d'avance pour votre aide.