Column mappings - can they be mapped per-object/table?

88 views
Skip to first unread message

willg...@gmail.com

unread,
Oct 3, 2016, 7:36:26 PM10/3/16
to sql2o
Having had bad experiences with hibernate, it seemed like sql2o is exactly what I've been looking for - cleans up jdbc boilerplate including copying object properties over, but otherwise I just write regular sql. 

The one concern I have looking through it is the "Columns Mappings" section -

Like say I have:

TableA
- name (object name "firstName")
- lastName

TableB
- name (object name "fullName")

But it looks from the docs like I might be screwed if I tried to use default column mappings for these, I'd end up with:
Map<String, String> colMaps = new HashMap<String,String>();
colMaps.put("name", "firstName");
colMaps.put("name", "fullName");
sql2o.setDefaultColumnMappings(colMaps);

Which would not work like I want because the second key would override the first.
Is there a way to do these mappings per-table other than writing out the mappings for each query I write?

willg...@gmail.com

unread,
Oct 5, 2016, 10:53:40 PM10/5/16
to sql2o, willg...@gmail.com
Lol...(silence)...crickets chirping...

Lars Aaberg

unread,
Oct 7, 2016, 6:09:43 AM10/7/16
to sql2o, willg...@gmail.com
It is not possible to add column mappings per table, but you can add column mappings per query.

try (Connection connection = sql2o.open()) {
connection.createQuery("select ...")
.addColumnMapping("name", "firstName")
.addParameter("...", "...")
.executeAndFetch(...);
}
Sorry for the late reply, btw :)

Regards
Lars Aaberg


On Thu, Oct 6, 2016 at 4:53 AM <willg...@gmail.com> wrote:
Lol...(silence)...crickets chirping...

--
You received this message because you are subscribed to the Google Groups "sql2o" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sql2o+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

willg...@gmail.com

unread,
Oct 11, 2016, 5:16:26 PM10/11/16
to sql2o, willg...@gmail.com
Thanks for the reply. :-)

Bummer though, looks like unfortunately that removes it from my list and the search for a simple jdbc framework continues for me. :-/
Reply all
Reply to author
Forward
0 new messages