我最近从oracle迁移到了postgres 10.1数据库。我通过sql查询手动创建了所有表,并确保不对表/列名使用任何双引号。
CREATE TABLE MYSCHEMA.SOMETABLE (ID VARCHAR(20) NOT NULL primary key, DISPLAYTEXT VARCHAR(100)));// skipping other column names for brevity
代码中的实体类
@Entity
@Table(name = "MYSCHEMA", schema = "SOMETABLE")
public class SomeTable implements Serializable {
private static final long serialVersionUID = -4856666041227614340L;
@Column(name = "VERSION")
private String version;
@Column(name = "DISPLAYTEXT")
private String displayText;
//other columns
}
使用Jpa存储库,我正在查询该表。
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
entityManagerFactoryRef = "someEntityManagerFactoryContentDB",
transactionManagerRef = "sometransactionManagerContentDB",
basePackages = {"com.somepath.repository.content"})
public interface SomeSearchConfigRepository extends JpaRepository<SomeTable, String> {
List<SomeTable> findBySearchTypeAndActiveOrderBySequenceAsc(
String searchType, String active);
}
问题在于它无法找到该表,并抛出以下错误。
2019-06-24 09:56:26,781 WARN org.hibernate.engine.jdbc.spi.SqlExceptionHelper:SQL Error: 0, SQLState: 42P01
2019-06-24 09:56:26,782 ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper:ERROR: relation "MYSCHEMA.SOMETABLE" does not exist
根据日志生成的sql
Hibernate:
/* select
generatedAlias0
from
SomeTable as generatedAlias0
where
(
generatedAlias0.searchType=:param0
)
and (
generatedAlias0.active=:param1
)
order by
generatedAlias0.sequence asc */ select
myalias_."ID" as ID1_3_,
myalias_."ACTIVE" as ACTIVE2_3_,
myalias_."COLUMNNAME" as COLUMNNA3_3_,
myalias_."DATATYPE" as DATATYPE4_3_,
myalias_."DISPLAYTEXT" as DISPLAYT5_3_,
myalias_."LENGTH" as LENGTH6_3_,
myalias_."LINKCOLUMN" as LINKCOLU7_3_,
myalias_."LINKSEARCH" as LINKSEAR8_3_,
myalias_."LOOKUPCOLUMN" as LOOKUPCO9_3_,
myalias_."LOOKUP_CATEGORY" as LOOKUP_10_3_,
myalias_."MULTISELECT" as MULTISE11_3_,
myalias_."REFERENCEKEY" as REFEREN12_3_,
myalias_."REFERENCETABLENAME" as REFEREN13_3_,
myalias_."REFERENCEVALUE" as REFEREN14_3_,
myalias_."SEARCHTYPE" as SEARCHT15_3_,
myalias_."SEQUENCE" as SEQUENC16_3_,
myalias_."TABLENAME" as TABLENA17_3_,
myalias_."VERSION" as VERSION18_3_
from
"MYSCHEMA"."SOMETABLE" myalias_
where
myalias_."SEARCHTYPE"=?
and myalias_."ACTIVE"=?
order by
myalias_."SEQUENCE" asc
是不是因为实体类中的注释导致了此问题?这里出了什么问题?如何在代码中进行最少的更改即可解决此问题?
答案 0 :(得分:1)
我假设您正在使用Spring Boot。
一种选择是告诉Hibernate不要引用名称
spring.jpa.properties.hibernate.globally_quoted_identifiers=false
或者另一种选择是用引号创建表并输入所有大写名称