Hi All,
I'm trying to write a ResultSetMapper that deals with UUID's. I'm using org.jdbi:jdbi:2.55, and org.postgresql:postgresql:9.3-1102-jdbc41, and postgres 9.3.
I've got a table with a column named "id" and type "uuid". I'm trying to get that value out of the ResultSet.
@Override
public UserSession map(int index, ResultSet r, StatementContext ctx) throws SQLException {
Object a = r.getObject(1);
return new UserSession(
UUID.fromString(r.getString("id")),
r.getLong("user_id"));
}
Here's the value of "a" as formatted by the eclipse variables panel. Hopefully this is clear to everyone.
a PGobject (id=274)
type "record" (id=276)
value "(b84dae7e-83b4-4635-84f8-c7ea32335d68,7)" (id=275)
I saw someone else try to do
something similar, where they called r.getObject(1) and cast the result to a UUID. That does not work for me, because the value that comes back is not a UUID, it's a PGobject.
The value "(b84dae7e-83b4-4635-84f8-c7ea32335d68,7)" is annoyingly different than the String representation of a UUID, since the UUID will not have parenthesis or the 7 at the end.
Also r.getString("id") throws an error, something along the lines of:
! org.postgresql.util.PSQLException: The column name id was not found in this ResultSet.
! at org.postgresql.jdbc2.AbstractJdbc2ResultSet.findColumn(AbstractJdbc2ResultSet.java:2728) ~[postgresql-9.3-1102-jdbc41.jar:na]
! at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getString(AbstractJdbc2ResultSet.java:2568) ~[postgresql-9.3-1102-jdbc41.jar:na]
! at com.kevinm416.report.user.UserSessionDBMapper.map(UserSessionDBMapper.java:15) ~[bin/:na]
! at com.kevinm416.report.user.UserSessionDBMapper.map(UserSessionDBMapper.java:1) ~[bin/:na]
Even though that column definitely exists, because I can see the value when I call r.getObject(1). I have also made very sure that the column is called "id" in the database.
Am I doing something wrong here? Does anyone have suggestions?
-Kevin