[4.0.1] Dynamic Mapping not working (using Jooq)

32 views
Skip to first unread message

Marcel Overdijk

unread,
Aug 29, 2018, 3:51:18 AM8/29/18
to SimpleFlatMapper
Hi,

I have a quite simple Continent table containing id, code and name columns.
I also have a Continent model class containing the same property with ordinary getters/setters following the bean specification.

For creating queries I'm using jOOQ for mapping I'm experimenting with the SimpleFlatMapper using ResultSets.

My code looks like:

JdbcMapper<Continent> continentJdbcMapper = JdbcMapperFactory
        .newInstance()
        .newBuilder(Continent.class)
        .mapper();

ResultSet rs = jooqDslContext
        .select(
            CONTINENT.ID,
            CONTINENT.CODE,
            CONTINENT.NAME)
        .from(CONTINENT)
        .where(CONTINENT.ID.eq(id))
        .fetchResultSet();

Continent continent = continentJdbcMapper.map(rs);


The problem is all properties of the continent instance are null; so mapping did not work.

I changed my continentJdbcMapper to static mapping like:

JdbcMapper<Continent> continentJdbcMapper = JdbcMapperFactory
        .newInstance()
        .newBuilder(Continent.class)
        .addMapping("id")
        .addMapping("code")
        .addMapping("name")
        .mapper();

and then it works.

I would have expected that dynamic mapping should be working or am I missing something?


Cheers,
Marcel


Arnaud Roger

unread,
Aug 29, 2018, 4:11:53 AM8/29/18
to Marcel Overdijk, SimpleFlatMapper
You will to call the newMapper(continent.class) instead of newBuilder().mapper()
The builder will return is to build static mapper which I’m your case has no columns

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "SimpleFlatMapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simpleflatmapp...@googlegroups.com.
To post to this group, send email to simplefl...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/simpleflatmapper/25ba9beb-b65d-4135-8df5-6369d189061f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcel Overdijk

unread,
Aug 29, 2018, 7:59:05 AM8/29/18
to SimpleFlatMapper
Thx!

I did not yet figure that out.

So when keys that it would be:

        countryJdbcMapper = JdbcMapperFactory
                .newInstance()
                .addKeys("country_id", "y", "z")
                .newMapper(Country.class);
Reply all
Reply to author
Forward
0 new messages