Not clear how to return multiple columns using SQL union()

Bug #754955 reported by cowwoc on 2011-04-08
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Fix Released

Bug Description

I am attempting to execute a UNION of three separate SQL queries as follows:

  QQueues q = QQueues.queues;
  QQueueDoctors qd = QQueueDoctors.queueDoctors;
  QAppointments a = QAppointments.appointments;
  List<Object[]> rows = session.query().union(
   leftJoin(a).on(a.queueId.eq(, qd.doctorId,,
   rightJoin(a).on(a.queueId.eq(, qd.doctorId,,
   rightJoin(a).on(a.queueId.eq(, qd.doctorId,

Unfortunately, this query always returns 0 columns because UnionBuilder.list() won't allow me to specify which columns should be returned.

1. AbstractSQLQuery.UnionBuilder.list() uses union[0].getMetadata().getProjection() to determine the number of columns to return. This returns 3 for me. But later on this method invokes iterateMultiple() and...
2. iterateMultiple() invokes getMetadata().getProjection() to find out how many columns should be returned. This returns 0 for me.

As a result I end I with a List containing one element of zero columns even though it should have 3 columns. This bug is related to

Fixed. The QueryMetadata instance of the first union child is now used.

Changed in querydsl:
status: New → Fix Committed

Released in 2.2.0-beta4

Changed in querydsl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers