Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.3k views
in Technique[技术] by (71.8m points)

java - Use inline literal instead of expression for oracle json_value function

I am using javax.persistence.criteria.CriteriaBuilder and I am having trouble using the persistence API to do this simple (oracle) SQL: SELECT * FROM foo ORDER BY json_value(json_text, '$.type');

What I have is

CriteriaBuilder cb= em.getCriteriaBuilder();
CriteriaQuery<Foo> query= cb.createQuery(Foo.class);
Root<QcJob> r = query.from(Foo.class);

Expression exp = cb.function("json_value", String.class, r.get("json_text"), cb.literal("$.type"));
query.orderBy(exp);

I get the following error ORA-40454: path expression not a literal because the underlying hibernate implementation generates this SQL: SELECT * FROM foo foo0_ order by json_value(foo0_.json_text, ?)

Oracle requires there to be a literal and no expression replacement. I found this https://stackoverflow.com/a/48721133/1738539, but I do not have org.hibernate.jpa.criteria.expression.LiteralExpression as I want to keep this agnostic to any specific implementation.

Is there anyway other way I can supply hibernate the inline literal for this function?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...