can we use subquery in .list() of a main query in QueryDSL? Please reply ASAP.

1,044 views
Skip to first unread message

pradeep gupta

unread,
Nov 5, 2015, 2:53:50 AM11/5/15
to Querydsl

Here is the java code snippet what I am trying to do.

SQLQuery query1 = new SQLQuery(conn, configuration); 

SQLSubQuery sql = new SQLSubQuery().from(user).where(user.firstName.eq("Pradeep"));

List<List<String>> tupleList = query1.from(user).list(sql.list(user.firstName));

The last line is having a null pointer exception.

with cause = null java.lang.NullPointerException: null at com.mysema.query.sql.JavaTypeMapping.findType(JavaTypeMapping.java:129) ~[querydsl-sql-3.6.1.jar:na] at com.mysema.query.sql.JavaTypeMapping.getType(JavaTypeMapping.java:108) ~[querydsl-sql-3.6.1.jar:na] at com.mysema.query.sql.Configuration.getType(Configuration.java:316) ~[querydsl-sql-3.6.1.jar:na] at com.mysema.query.sql.Configuration.get(Configuration.java:208) ~[querydsl-sql-3.6.1.jar:na] at com.mysema.query.sql.AbstractSQLQuery.get(AbstractSQLQuery.java:111) ~[querydsl-sql-3.6.1.jar:na] at com.mysema.query.sql.AbstractSQLQuery.list(AbstractSQLQuery.java:347) ~[querydsl-sql-3.6.1.jar:na]

timowest

unread,
Nov 5, 2015, 1:43:40 PM11/5/15
to Querydsl
What kind of SQL do you want to express?

pradeep gupta

unread,
Nov 6, 2015, 5:39:18 AM11/6/15
to Querydsl
The actual sql is different but I want to achieve an equivalent of 

select (select distinct USER.first_name from USER USER where USER.first_name = 'Pradeep') from USER USER

List<List<String>> tupleList = query1.from(user).list(sql.distinct().list(user.firstName));

Above line is creating the same query in the logs.

[DEBUG] com.mysema.query.sql.AbstractSQLQuery - select (select distinct USER.first_name from USER USER where USER.first_name = ?) from USER USER

But execution is getting terminated by throwing null pointer exception with the mentioned stacktrace.

Please note the query is returning result when I am executing it in database directly.

pradeep gupta

unread,
Nov 13, 2015, 10:55:56 AM11/13/15
to Querydsl
@Timo.....I am still waiting for a solution. Please help me.


On Thursday, 5 November 2015 13:23:50 UTC+5:30, pradeep gupta wrote:

timowest

unread,
Nov 13, 2015, 3:07:34 PM11/13/15
to Querydsl
Hi, sorry for the delay.

The following works:

List<List<String>> tupleList = query1.from(user).unique(sql.list(user.firstName));

I will fix the list behaviour for subqueries.

pradeep gupta

unread,
Nov 16, 2015, 12:29:04 AM11/16/15
to Querydsl
Hi Timo,

Thanks for your reply. Above code snippet is replica what I am trying to do. Actual code is different. In that I need 

query.list(subquery.list(...), ....)

So I think until you fix that in your next release, I will not be able to proceed further.

Please comment if you have any suggestion.


On Thursday, 5 November 2015 13:23:50 UTC+5:30, pradeep gupta wrote:

timowest

unread,
Nov 16, 2015, 12:03:49 PM11/16/15
to Querydsl
Sorry, my fix example was wrong, try:

List<List<String>> tupleList = query1.from(user).list(sql.unique(user.firstName));
Reply all
Reply to author
Forward
0 new messages