雪花返回大写字段结果集,导致 jpql 映射 jpa/hibernate 问题

发布于 2025-01-19 07:53:54 字数 1875 浏览 0 评论 0 原文

我有一个项目可以使用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

The Resultset from snowflake returns

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云淡月浅 2025-01-26 07:53:54

请参阅:如何向别名添加引号通过 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文