我正在尝试使用Spring Jpa从postgres获取记录。 Postgres中的所有表和列都是大写的,但是spring jpa以小写的形式生成查询,尽管我在实体类中提到了大写的表名。我已经在这个类似的问题上经历了很多关于stackoverflow的帖子,并且每个人都建议将命名策略添加到我所做的yaml文件中,但仍然以小写形式生成表名。我已经使用了以下策略(每次都使用,但对我来说没有任何效果)。我错过了别的什么吗?
spring.jpa.properties.hibernate.naming.physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.naming_strategy: org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.properties.hibernate.naming.implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
Caused by: **org.postgresql.util.PSQLException: ERROR: relation "**table_name**" does not exist**
Position: 258
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2455)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2155)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:288)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:430)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:356)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:168)
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:116)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.jdbc.pool.StatementFacade$StatementProxy.invoke(StatementFacade.java:114)
at com.sun.proxy.$Proxy201.executeQuery(Unknown Source)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:60)
... 179 common frames omitted
这是我添加到yaml文件中的属性:
spring.jpa.properties.database-platform: org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.id.new_generator_mappings: true
spring.jpa.properties.hibernate.cache.use_second_level_cache: true
spring.jpa.properties.hibernate.cache.use_query_cache: false
spring.jpa.properties.hibernate.generate_statistics: true
spring.jpa.properties.hibernate.cache.region.factory_class: io.github.jhipster.config.jcache.NoDefaultJCacheRegionFactory
spring.jpa.properties.hibernate.naming-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
#hibernate.naming_strategy: org.hibernate.cfg.EJB3NamingStrategy
#hibernate.naming.implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
#hibernate.dialect: org.hibernate.dialect.PostgreSQLDialect
答案 0 :(得分:0)
我以这种方式复制了你需要的东西:
CREATE TABLE temp."SOME_UPPERCASE_TABLE" (
dt TIMESTAMP NOT NULL DEFAULT now(),
column1 VARCHAR(10) PRIMARY KEY
);
实体:
@Entity
@Table(name = "SOME_UPPERCASE_TABLE", schema = "tmp", catalog = "cram")
public class SomeUppercaseTableEntity {
private Timestamp dt;
private String column1;
// getters, setters...
一切都运作良好。