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

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

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(
   session.subQuery(q).where(q.id.eq(queueId.getId())).
   leftJoin(qd).on(qd.queueId.eq(q.id)).
   leftJoin(a).on(a.queueId.eq(q.id)).list(q.name, qd.doctorId, a.id),
   session.subQuery(q).where(q.id.eq(queueId.getId())).
   leftJoin(qd).on(qd.queueId.eq(q.id)).
   rightJoin(a).on(a.queueId.eq(q.id)).list(q.name, qd.doctorId, a.id),
   session.subQuery(q).where(q.id.eq(queueId.getId())).
   rightJoin(qd).on(qd.queueId.eq(q.id)).
   rightJoin(a).on(a.queueId.eq(q.id)).list(q.name, qd.doctorId, a.id)).
   list();

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 https://bugs.launchpad.net/querydsl/+bug/754910

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