Queries returning arrays are being wrapped in Object[] #1004

Closed
cowwoc opened this Issue Oct 11, 2014 · 1 comment

Comments

Projects
None yet
2 participants
@cowwoc
Contributor

cowwoc commented Oct 11, 2014

If a user invokes:

QAuthentication a = QAuthentication.authentication;
List<byte[]> foo = session.query(a).where(a.userId.eq(userId)).list(a.id);

where a.id is of type byte[] then the Query returns the wrong type. Instead of a List<byte[]> it returns a List<Object[]> where the list contains a Object[] and that array, in turn, contains byte[] per element. What is more confusing is that the above code does not generate a compile-time error.

Expected behavior: Query should return a List<byte[]>.

I believe you can fix this issue by doing the following:

AbstractSQLQuery:257 reads;

                        while (rs.next()) {
                            Object[] row = new Object[rs.getMetaData().getColumnCount()];
                            if (getLastCell) {
                                lastCell = rs.getObject(row.length);
                                getLastCell = false;
                            }
                            for (int i = 0; i < row.length; i++) {
                                row[i] = rs.getObject(i+1);
                            }
                            rv.add((RT)row);
                        }

I would replace it with the following code:

                        while (rs.next()) {
                            if (getLastCell) {
                                lastCell = rs.getObject(row.length);
                                getLastCell = false;
                            }
                            for (int i = 0; i < row.length; i++) {
                                rv.add((RT)rs.getObject(i+1));
                            }
                        }
@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Oct 12, 2014

Member

This part was originally a wildcard detection. I added a PR which does the detection properly.

Member

timowest commented Oct 12, 2014

This part was originally a wildcard detection. I added a PR which does the detection properly.

@timowest timowest added this to the 3.5.1 milestone Oct 12, 2014

@timowest timowest added the bug label Oct 12, 2014

@timowest timowest closed this in #1005 Oct 14, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment