Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring boot和Postgres的JPA请求中存在问题_Java_Postgresql_Spring Boot_Jpa - Fatal编程技术网

Java Spring boot和Postgres的JPA请求中存在问题

Java Spring boot和Postgres的JPA请求中存在问题,java,postgresql,spring-boot,jpa,Java,Postgresql,Spring Boot,Jpa,已解决 在服务器上,表是使用默认数据库创建的,而不是使用pgsql创建的。现在,我需要检查是否有办法在SQL脚本中精确显示数据库,或者为我的特定用户设置默认数据库。 我的Spring Boot web应用程序中的查询有一个奇怪的问题。它是一个在Tomcat上运行的maven java Web应用程序,使用JPA和criterias,带有Postgres DB。 该应用程序在我的Windows电脑上运行良好,本地有Postgres 11和Tomcat 9 我在debian服务器(Postgres

已解决 在服务器上,表是使用默认数据库创建的,而不是使用pgsql创建的。现在,我需要检查是否有办法在SQL脚本中精确显示数据库,或者为我的特定用户设置默认数据库。


我的Spring Boot web应用程序中的查询有一个奇怪的问题。它是一个在Tomcat上运行的maven java Web应用程序,使用JPA和criterias,带有Postgres DB。 该应用程序在我的Windows电脑上运行良好,本地有Postgres 11和Tomcat 9

我在debian服务器(Postgres、Tomcat)上也有同样的功能,但当我在Tomcat上部署war时,SQL查询不起作用:

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
我在模式配置方面做了很多尝试,修改了直接使用hibernate属性、jpa属性和hikari属性配置默认模式的方法。。。 如果是架构问题或案例问题,我目前为每个实体都提供了以下注释(我不太喜欢),但仍然无法正常工作:

@Table(name = "reseau", schema = "my_schema")
以下是日志中显示的查询:

select reseau0_.id as id1_10_, reseau0_.nom as nom2_10_ from my_schema.reseau reseau0_
当在服务器上以psql的方式执行它时,它正在工作

你能帮帮我吗?我现在有点困了…非常感谢

这是我的持久性配置文件:

@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;
}
@配置
@组件扫描
@启用事务管理
@授权代理
公共类PersistenceJPAConfig{
@豆子
public LocalContainerEntityManagerFactoryBean entityManagerFactory(){
LocalContainerEntityManagerFactoryBean em=新的LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(新字符串[]{“com.company.project.server.dao.model”});
JpaVendorAdapter=new HibernateJpaVendorAdapter();
em.setjpavendor适配器(供应商适配器);
em.setJpaProperties(additionalProperties());
返回em;
}
@豆子
公共数据源数据源(){
DataSourceBuilder DataSourceBuilder=DataSourceBuilder.create();
dataSourceBuilder.driverClassName(“org.postgresql.Driver”);
url(“jdbc:postgresql://127.0.0.1:5433/db");
dataSourceBuilder.username(“登录”);
dataSourceBuilder.密码(“xxxxxxxx”);
返回dataSourceBuilder.build();
}
@豆子
公共平台transactionManager transactionManager(EntityManager工厂emf){
JpaTransactionManager transactionManager=新的JpaTransactionManager();
transactionManager.setEntityManagerFactory(emf);
返回事务管理器;
}
@豆子
公共持久性ExceptionTranslationPostProcessor exceptionTranslation(){
返回新的PersistenceExceptionTranslationPostProcessor();
}
属性附加属性(){
属性=新属性();
setProperty(“spring.jpa.properties.hibernate.dialent”、“org.hibernate.dialent.postgresql95dialent”);
//setProperty(“spring.jpa.properties.hibernate.default_schema”、“my_schema”);
setProperty(“spring.jpa.properties.hibernate.hikari.dataSource.currentSchema”,“my_schema”);
setProperty(“spring.jpa.show sql”,“true”);
setProperty(“spring.jpa.properties.hibernate.format_sql”,“true”);
setProperty(“spring.jpa.properties.hibernate.id.new_生成器_映射”,“true”);
归还财产;
}

}

为什么需要在那里使用模式?你能试着从实体注释中删除它吗?我想debian服务器上没有必要的注释。Debian Postgres服务器上是否已经存在所有表?如果没有,请确保已按中所述设置属性。@ArmandoBallaci感谢您的帮助。我一直在尝试一些事情,因为没有这个模式,查询中没有提到它,查询是:select…from reseau而不是my_schema.reseau。spring.jpa.properties.hibernate.hikari.dataSource.currentSchema和spring.jpa.properties.hibernate.default_架构都不起作用。我尝试了使用和不使用批注,但仍然不起作用。@spring感谢您的帮助。数据库中的一切都正常。我有一个用于创建它的SQL脚本,我在本地(它工作的地方)和服务器上使用相同的脚本。数据库中存在查询要查找的架构和表(在运行\dt my_schema.*的服务器上使用pgsql进行检查)。