JPA Top Level Table Names

I have a table in Postgresql:

CREATE TABLE "UTILISATEUR"( "IdUtilisateur" serial NOT NULL, "Nom" character varying(50), "Prenom" character varying(50), "Profil" character varying(50), "Pseudo" character varying(20), "IdSite" integer DEFAULT 0, "Password" character varying(1024), id_role integer, ) 

and I'm trying to use a map on this table. Therefore, I used the @Table JPA annotation (see below). This is my application.propreties :

 spring.datasource.url = jdbc:postgresql://localhost/baseecu spring.datasource.username = postgres spring.datasource.password =root spring.datasource.driverClassName=org.postgresql.Driver spring.jpa.database = MYSQL spring.jpa.show-sql = true spring.jpa.hibernate.ddl-auto=update spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect 

and finally this is my entity class:

 @Entity @Table(name="UTILISATEUR") public class Utilisateur { @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="IdUtilisateur") public Long id ; public String Nom ; public String Prenom ; public String Profil ; public String Pseudo ; public String Password ; @ManyToOne @JoinColumn(name="id_role") public Role role ; public Long getId() { return id; 

If I have it as @Table(name="UTILISATEUR") , I get msg from PostgreSQL

 ERREUR: la relation « utilisateur » n'existe pas 

When I try to avoid the quote @Table(name="\"UTILISATEUR\"")

 ERROR: syntax error at or near "`" 

I tried to answer this question, but it does not work

Spring load JPA paste into TABLE with uppercase name with Hibernate

Update

I searched for the ImprovedNamingstrategy problem, it seems the spring loading problem, instead I used EJB3NamingStrategy as well as DefaultNamingStrategy, not working on what is funny when Hibernate is executing SQL, the result is rather confusing:

 Hibernate: select utilisateu0_.IdUtilisateur as IdUtilis1_2_, utilisateu0_.Nom as Nom2_2_, utilisateu0_.Password as Password3_2_, utilisateu0_.Prenom as Prenom4_2_, utilisateu0_.Profil as Profil5_2_, utilisateu0_.Pseudo as Pseudo6_2_, utilisateu0_.id_role as id_role7_2_ from UTILISATEUR utilisateu0_ 

He likes that the table name is in UPPERCASE, but doesn’t want to display the map or I don’t know what is wrong with it, this is the result of using

 spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.DefaultNamingStrategy or spring.jpa.hibernate.naming_strategy = org.hibernate.cfg.DefaultNamingStrategy 

as well as EJB3NamingStrategy

This is also the result when I use such annotation

 @Table(name="UTILISATEUR") 

and I tried it too

 @Table(name="\"UTILISATEUR\"") 

and i get a problem

 ERROR: syntax error at or near "`" Hibernate: select utilisateu0_.IdUtilisateur as IdUtilis1_2_, utilisateu0_.Nom as Nom2_2_, utilisateu0_.Password as Password3_2_, utilisateu0_.Prenom as Prenom4_2_, utilisateu0_.Profil as Profil5_2_, utilisateu0_.Pseudo as Pseudo6_2_, utilisateu0_.id_role as id_role7_2_ from `UTILISATEUR` utilisateu0_ 

Finally this is my pom.xml

 <?xml version="1.0" encoding="UTF-8"?> <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.xx.MDValidation</groupId> <artifactId>xx.MDValidation</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>xx.MDValidation</name> <description>Projet Validation xx</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.2.RELEASE</version> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> <hibernate.version>4.2.21.Final</hibernate.version> <commons-dbcp.version>1.2.2</commons-dbcp.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>postgresql</groupId> <artifactId>postgresql</artifactId> <version>9.1-901.jdbc4</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jooq</artifactId> </dependency> <dependency> <groupId>bsf</groupId> <artifactId>bsf</artifactId> <version>2.4.0</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> 

+10
spring-boot postgresql hibernate jpa
source share
5 answers

maybe because you use MYSQL5DIALECT where Postgres Dialect just used post it like this and to improve your naming strategy use EJB3 like Spring Load JPA paste into TABLE with uppercase with Hibernate

 spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect 

hope this works for you.

+8
source share

I reproduced your UTILISATEUR table (role removed) in postgres 8.4 and hibernate 5.0.3.

It works as expected with explicit annotation of columns and columns:

 @Entity(name="\"UTILISATEUR\"") public class Utilisateur { @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="\"IdUtilisateur\"") private Long id ; @Column(name="\"Nom\"") private String Nom ; @Column(name="\"Prenom\"") private String Prenom ; @Column(name="\"Profil\"") private String Profil ; @Column(name="\"Pseudo\"") private String Pseudo ; @Column(name="\"Password\"") private String Password ; ... getter / setters } 
+7
source share

If the problem is in the upper case ... as in the title - please go to this page: http://docs.jboss.org/hibernate/orm/3.6/javadocs/org/hibernate/cfg/ImprovedNamingStrategy.html This way you can force the names of the tables with the upper obsan.

+1
source share

You can configure your application with the following line depending on the database:

Mysql

 spring.jpa.hibernate.naming_strategy = org.hibernate.cfg.DefaultNamingStrategy 

Postgres

 spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect 

oracle

 spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect 
0
source share

I ran into the same problem and I again indicated (') my table name in the entity declaration, for example, “UTILISATEUR”. @Table(name = " 'UTILISATEUR'")

'using postgresql 11 with dialect: org.hibernate.dialect.PostgreSQL95Dialect, he generated me an elevated table name in the database.

-3
source share

All Articles