My SQL query takes a list of email addresses, and returns the account number associated with each one. I'm trying to write a SQL Object method which returns a
Map<String, String> with the email -> account number mappings, like so:
@UseStringTemplate3StatementLocator
@SqlQuery("select email, account_number from customer where email in (<emails>)")
public Map<String, String> getAccountNumbers(@BindIn("emails") Collection<String> emails);
However, I can't figure out how to use @RegisterContainerMapper (and possibly @RegisterMapper) to make this work. The error I'm getting is:
org.skife.jdbi.v2.MappingRegistry$1: No mapper registered for java.util.Map
at org.skife.jdbi.v2.MappingRegistry.mapperFor(MappingRegistry.java:83)
at org.skife.jdbi.v2.RegisteredMapper.map(RegisteredMapper.java:35)
at org.skife.jdbi.v2.Query$4.munge(Query.java:183)
at org.skife.jdbi.v2.QueryResultSetMunger.munge(QueryResultSetMunger.java:41)
at org.skife.jdbi.v2.SQLStatement.internalExecute(SQLStatement.java:1343)
at org.skife.jdbi.v2.Query.fold(Query.java:173)
at org.skife.jdbi.v2.Query.first(Query.java:273)
at org.skife.jdbi.v2.Query.first(Query.java:264)
at org.skife.jdbi.v2.sqlobject.ResultReturnThing$SingleValueResultReturnThing.result(ResultReturnThing.java:110)
at org.skife.jdbi.v2.sqlobject.ResultReturnThing.map(ResultReturnThing.java:46)
at org.skife.jdbi.v2.sqlobject.QueryHandler.invoke(QueryHandler.java:43)
at org.skife.jdbi.v2.sqlobject.SqlObject.invoke(SqlObject.java:212)
at org.skife.jdbi.v2.sqlobject.SqlObject$2.intercept(SqlObject.java:109)
at org.skife.jdbi.v2.sqlobject.CloseInternalDoNotUseThisClass$$EnhancerByCGLIB$$8a8bd544.getCustomerUtilityIds(<generated>)
Is there a way to do this?
The closest things I found were:
1) Denis's WithoutNullsListContainerFactory, which is the only example I could find of a SQL Object query using both annotations (@RegisterContainerMapper and @RegisterMapper):
2) TestContainerFactory using a non-iterable container type (called "Maybe"), albeit still with a single value type, instead of two or more like a Map:
Thanks in advance! Folks at my company use JDBI a ton. :)
-Steve