org.hibernate.query.sqm.InterpretationException

908 views
Skip to first unread message

Jignesh Patel

unread,
Apr 30, 2023, 9:21:52 PM4/30/23
to Quarkus Development mailing list
This is how my code looks
ublic Users getUser(Users users){
Users usersResult = null;
StringBuilder sql = new StringBuilder();
try {
//sql.append("SELECT u from Users u where 1=1");
sql.append("SELECT u from Users u where 1=1");
if (users.getUserId() != null) {
sql.append(" AND u.userId ='" + users.getUserId() + "'");
}

if (users.getCustomer() != null) {
if (users.getCustomer().getCustomerId() != null) {
sql.append(" AND u.customer.customerId ='" + users.getCustomer().getCustomerId() + "'");
}
if (users.getCustomer().getId() != null) {
sql.append(" AND u.customer.id ='" + users.getCustomer().getId() + "'");
}
}


TypedQuery<Users> q = em.createQuery(sql.toString(), Users.class);
usersResult = q.getSingleResult();
} catch (Exception e) {
logger.error("Getting Exception getUser "+e.getMessage());
return null;
}
return usersResult;
}

I am getting the following exception
ERROR [co.ic.bi.re.UserRepository] (main) Getting Exception getUser org.hibernate.query.sqm.InterpretationException: Error interpreting query [SELECT u from Users u where 1=1 AND u.userId ='071e4b35-7a7a-4f6a-b9fb-c7eecac65c45' AND u.customer.id ='19']; this may indicate a semantic (user query) problem or a bug in the parser [SELECT u from Users u where 1=1 AND u.userId ='071e4b35-7a7a-4f6a-b9fb-c7eecac65c45' AND u.customer.id='19']
If I remove the call of u.customer.id then the query works. I checked the sql in db and looks ok, but my test case fails, so seems hibernate ORM doesn't like it.

This is how the user entity lazily loads the customer object.
@JoinColumn(name = "CUSTOMER_ID", referencedColumnName = "ID", nullable =false)
@ManyToOne(fetch = FetchType.LAZY)
private Customer customer;


Yoann Rodiere

unread,
May 1, 2023, 3:12:17 AM5/1/23
to jignes...@gmail.com, Quarkus Development mailing list
Hey,

We've told you before, this mailing list is for the development of Quarkus itself, not for usage problems or bug reports.

For support, use GitHub discussions: https://github.com/quarkusio/quarkus/discussions
Or open issues if you suspect the problem is in Quarkus and not in your app, ideally with a reproducer: https://github.com/quarkusio/quarkus/issues

In this specific case, there seems to be a problem with Hibernate ORM itself, not with Quarkus, so you'd ideally report it directly to the Hibernate ORM project: https://hibernate.atlassian.net/jira/software/c/projects/HHH/issues

Cheers,
Yoann Rodière
Hibernate Team


--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/quarkus-dev/CAHTx_0z%2BF354yd4z3zo_%2BbNQLJXNppB8u4FrXJhKLEp1-oL2NQ%40mail.gmail.com.

Jignesh Patel

unread,
May 1, 2023, 9:14:26 AM5/1/23
to Yoann Rodiere, Quarkus Development mailing list
My apologies. 
Reply all
Reply to author
Forward
0 new messages