简体   繁体   中英

How to get json column value in postgresql with querydsl?

Our prjoect configurations are

  • Spring Boot:: (v2.6.0)
  • Java 11.0.15
  • Hibernate ORM core version 5.6.1.Final
  • com.vladmihalcea:hibernate-types-55:2.20.0

I'd like get json column value.

The json column is here:

在此处输入图像描述

在此处输入图像描述

How can I get "isOption1" property in json column?

The query is here:

在此处输入图像描述

By the way, running the query caused an "QuerySyntaxException".

org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: with near line 2, column 63 [select tranOrdTest.uid, tranOrdTest.tranOrdKey, tranOrdTest.tranCarOption, tranOrdTest_tranCarOption_0 as isOption1 from tranOrdTest.tranCarOption as tranOrdTest_tranCarOption_0 with key(tranOrdTest_tranCarOption_0) =?1, kr.co.conc.deliveryserver.biz.tr.tranOrd.entity.TranOrdTest tranOrdTest]; nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: with near line 2, column 63 [select tranOrdTest.uid, tranOrdTest.tranOrdKey, tranOrdTest.tranCarOption, tranOrdTest_tranCarOption_0 as isOption1 from tranOrdTest.tranCarOption as tranOrdTest_tranCarOption_0 with key(tranOrdTest_tranCarOption_0) =?1, kr.co.conc.deliveryserver.biz.tr.tranOrd.entity.TranOrdTest tranOrdTest] org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: with near line 2, column 63 [select tranOrdTest.uid, tranOrdTest.tranOrdKey, tranOrdTest.tranCarOption, tranOrdTest_tranCarOption_0 as isOption1 from tranOrdTest.tranCarOption as tranOrdTest_tranCarOption_0 with key(tranOrdTest_tranCarOption_0) =?1, kr.co.conc.deliveryserver.biz.tr.tranOrd.entity.TranOrdTest tranOrdTest]; nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: with near line 2, column 63 [select tranOrdTest.uid, tranOrdTest.tranOrdKey, tranOrdTest.tranCarOption, tranOrdTest_tranCarOption_0 as isOption1 from tranOrdTest.tranCarOption as tranOrdTest_tranCarOption_0 with key(tranOrdTest_tranCarOption_0) =?1, kr.co.conc.deliveryserver.biz.tr.tranOrd.entity.TranOrdTest tranOrdTest]

SO how can I resolve this issue?

Please comment if you have the solution for this issue.

Thanks.

I don't want to use native query; I want to use querydsl method.

Query is working except getting json value

在此处输入图像描述

but query is not working include the json value.

I want to get "isOption1" property.

Please let me know how can I do that.

Thanks.

You can use Hibernate 6.2 for this purpose, which allows you to map an @Embeddable to a JSON column like this:

@JdbcTypeCode(SqlTypes.JSON)
@Column(name = "trancaroptions")
TranCarOptions options;

record TranCarOptions(String isOption1 ,String isOption2, String isOption3, String isOption4, String isOption5) {}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM