SOLVED On the server, the tables had been created with the default database instead of mine using pgsql. Now I need to check if there is a way to precise the database in an SQL script, or to set up a default database for my specific user.
I am having a weird problem with the queries in my Spring Boot web app. It is a maven java webapp running on Tomcat, using JPA and criterias, with a Postgres DB. The app is working fine on my Windows computer, with a local Postgres 11 and Tomcat 9.
I have the same on a debian server (Postgres, Tomcat), but when I am deploying the war on the Tomcat, SQL queries are not working :
Caused by: org.postgresql.util.PSQLException: ERROR: relation "my_schema.reseau" does not exist
Position: 62
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2497)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2233)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:310)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:446)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:370)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:149)
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:108)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:57)
... 134 common frames omitted
I have tried many things with the schema configuration, modifying the way to configure the default schema directly with hibernate properties, with jpa properties, with hikari properties... In case it would have been a schema problem or a case problem, I am currently having the following annotation for every entity (which I don't like much), but still not working anyway :
@Table(name = "reseau", schema = "my_schema")
Here is the query as displayed in the logs :
select reseau0_.id as id1_10_, reseau0_.nom as nom2_10_ from my_schema.reseau reseau0_
When executing it as is in psql on the server, it is working!
Could you please help me? I am a bit stuck for the moment...Thanks a lot!
Here is my persistence configuration file :
@Configuration
@ComponentScan
@EnableTransactionManagement
@EnableJpaRepositories
public class PersistenceJPAConfig {
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(new String[] { "com.company.project.server.dao.model" });
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(additionalProperties());
return em;
}
@Bean
public DataSource dataSource() {
DataSourceBuilder<?> dataSourceBuilder = DataSourceBuilder.create();
dataSourceBuilder.driverClassName("org.postgresql.Driver");
dataSourceBuilder.url("jdbc:postgresql://127.0.0.1:5433/db");
dataSourceBuilder.username("login");
dataSourceBuilder.password("xxxxxxxx");
return dataSourceBuilder.build();
}
@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(emf);
return transactionManager;
}
@Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
Properties additionalProperties() {
Properties properties = new Properties();
properties.setProperty("spring.jpa.properties.hibernate.dialect", "org.hibernate.dialect.PostgreSQL95Dialect");
//properties.setProperty("spring.jpa.properties.hibernate.default_schema", "my_schema");
properties.setProperty("spring.jpa.properties.hibernate.hikari.dataSource.currentSchema", "my_schema");
properties.setProperty("spring.jpa.show-sql", "true");
properties.setProperty("spring.jpa.properties.hibernate.format_sql", "true");
properties.setProperty("spring.jpa.properties.hibernate.id.new_generator_mappings", "true");
return properties;
}
}