-
-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ResultSetMapper for List<Map<String, Object>> for SqlQuery #81
Comments
Have solved it? I also meet the same problem. |
Hi, if you are getting an exception, can you please post the exact exception trace you are seeing? A self contained code example would also be useful if further debugging is necessary. |
I believe the problem is your mapper maps List<Map<String,Object>> instead
of just Map<String,Object>. ResultSetMapper maps a single row of a result
set. Putting it into a list is Query's job, not the mapper.
…-Matthew
On Jan 2, 2017 04:23, "Алексей Попрядухин" ***@***.***> wrote:
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:1344)
at org.skife.jdbi.v2.Query.fold(Query.java:173)
at org.skife.jdbi.v2.Query.list(Query.java:82)
at org.skife.jdbi.v2.sqlobject.ResultReturnThing$
IterableReturningThing.result(ResultReturnThing.java:253)
at org.skife.jdbi.v2.sqlobject.ResultReturnThing.map(
ResultReturnThing.java:46)
at org.skife.jdbi.v2.sqlobject.QueryHandler.invoke(QueryHandler.java:41)
at org.skife.jdbi.v2.sqlobject.SqlObject.invoke(SqlObject.java:220)
at org.skife.jdbi.v2.sqlobject.SqlObject$2.intercept(SqlObject.java:111)
at org.skife.jdbi.v2.sqlobject.CloseInternalDoNotUseThisClass
$$EnhancerByCGLIB$$33103a76.selectTempChatMessages()
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#81 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AACW5cJdVzRYKloa4Q-kOIfF6rgavit-ks5rON49gaJpZM4BEn1->
.
|
Try this: public class MapMapper implements ResultSetMapper<Map<String, Object>> {
@Override
public Map<String, Object> map(int index, ResultSet r, StatementContext ctx) throws SQLException {
Map<String, Object> map = new HashMap<String, Object>();
for (int i = 1; i <= r.getMetaData().getColumnCount(); i++) {
map.put(r.getMetaData().getColumnLabel(), r.getObject(i));
}
return map;
}
} I should point out that the default mapper used by Query is already available as public API: org.skife.jdbi.v2.DefaultMapper. You can just use it directly if you want. |
@qualidafial , thanks a lot. This is the real help. I struggled like anything :) ultimately your answer is the correct one. |
How to do this in JDBI3? @Override
@SqlQuery("select * from "+table+" where articleId = :id")
@RegisterRowMapper(MapMapper.class)
Map<String, Object> rowAsMap(@Bind("id") int id);
@Override
@SqlQuery("select * from "+table+" where articleId>=:from AND articleId<:before")
@RegisterRowMapper(MapMapper.class)
List<Map<String, Object>> rowsAsMapList(@Bind("from") int from, @Bind("before") int before); |
Hi,
I'm trying to create mapper for regular SqlQuery in the same manner like handle.select that is returning
List of Map String, Object
Code example:
But I'm getting exception: unable to access mapper
The text was updated successfully, but these errors were encountered: