我有一个项目可以使用JPA/Hibernate的ORM与Snowflake数据库进行集成
但是,对于雪花的结果,总是会返回大写字段,与JPQL默认Behevior发生冲突。
下面的示例是使用jpql的选择查询,因为您可以看到所有字段都在
select podioitem0_.ID as id1_0_0_, podioitem0_.JSON as json2_0_0_ from INLIFE_MARK.PUBLIC.podio_item podioitem0_ where podioitem0_.ID=?
snowflake returns返回uppercase列
给定上面的样本,我会得到此错误
o.h.engine.jdbc.spi.SqlExceptionHelper : Column not found: json2_0_0_
,因为尝试映射 JSON2_0_0 _
resultset中的列无法找到映射器,因为ResultSet的列在大写上。
因此,是否有办法告诉JPQL或JPA/Hibernate在大写中生成JPQL查询?至少对于列名称,我希望它看起来像这样吗?
select podioitem0_.ID as ID1_0_0_, podioitem0_.JSON as JSON2_0_0_ from INLIFE_MARK.PUBLIC.podio_item podioitem0_ where podioitem0_.ID=?
下面的其他详细信息
属性
spring.jpa.show-sql=true
spring.jpa.database=SQL_SERVER
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.naming.implicit-
strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl
spring.jpa.hibernate.naming.physical-
strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServerDialect
示例实体类别
@ToString
@Entity
@Table(schema = "PUBLIC", catalog = "INLIFE_MARK", name = "podio_item")
public class PodioItem {
@Id
@Column(name = "id")
public Long id;
@Column(name = "json", columnDefinition="varbinary")
public byte[] json;
}
I正在使用crudrepository保存和查找
@Repository
public interface PodioItemRepository extends
CrudRepository<PodioItem, Long> {
}
我希望将某种属性作为解决方案的对象,但欢迎任何建议。
I have a project to do integration with snowflake database using ORM like JPA/Hibernate
but for the resultset from snowflakes always returns fields in UPPERCASE which conflicts with JPQL default behevior.
Example below is a select query using JPQL as you can see all fields are in lowercase
select podioitem0_.ID as id1_0_0_, podioitem0_.JSON as json2_0_0_ from INLIFE_MARK.PUBLIC.podio_item podioitem0_ where podioitem0_.ID=?
The Resultset from snowflake returns Uppercase columns
Given the samples above I get this error
o.h.engine.jdbc.spi.SqlExceptionHelper : Column not found: json2_0_0_
Its because when trying to map json2_0_0_
column from resultset the mapper cant find it because the columns from resultset are on uppercase.
So Question, is there a way to tell JPQL or jpa/hibernate to generate the JPQL query in Uppercase? at least for the column names so I hope it would look like this?
select podioitem0_.ID as ID1_0_0_, podioitem0_.JSON as JSON2_0_0_ from INLIFE_MARK.PUBLIC.podio_item podioitem0_ where podioitem0_.ID=?
Additional details below
properties
spring.jpa.show-sql=true
spring.jpa.database=SQL_SERVER
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.naming.implicit-
strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl
spring.jpa.hibernate.naming.physical-
strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServerDialect
Sample Entity Class
@ToString
@Entity
@Table(schema = "PUBLIC", catalog = "INLIFE_MARK", name = "podio_item")
public class PodioItem {
@Id
@Column(name = "id")
public Long id;
@Column(name = "json", columnDefinition="varbinary")
public byte[] json;
}
I am using CrudRepository to save and find objects
@Repository
public interface PodioItemRepository extends
CrudRepository<PodioItem, Long> {
}
I was hoping maybe somekind of property as a solution but any suggestion is welcome.
发布评论
评论(1)
请参阅:如何向别名添加引号通过 Hibernate 生成 sql?
只需将
&CLIENT_RESULT_COLUMN_CASE_INSENSITIVE=true
添加到雪花连接字符串即可。Please see: How to add quotes to aliases in generated sql via Hibernate?
Just add
&CLIENT_RESULT_COLUMN_CASE_INSENSITIVE=true
to your snowflake connection string.