arnaudroger / SimpleFlatMapper

Fast and Easy mapping from database and csv to POJO. A java micro ORM, lightweight alternative to iBatis and Hibernate. Fast Csv Parser and Csv Mapper
http://simpleflatmapper.org
MIT License
437 stars 76 forks source link

Error when trying to use JOOQ's Result to ResultSet #587

Closed estebes closed 5 years ago

estebes commented 5 years ago

When using JOOQ and using .fetch().intoResultSet() instead of .fetchResultSet() I get an exception:

java.lang.IllegalStateException: No date format specified at org.simpleflatmapper.converter.impl.time.JavaTimeHelper.getDateTimeFormatters(JavaTimeHelper.java:56) at org.simpleflatmapper.converter.impl.time.AbstractMultiFormatContextualConverterFactory.newConverter(AbstractMultiFormatContextualConverterFactory.java:20) at org.simpleflatmapper.converter.ConverterService.findConverter(ConverterService.java:90) at org.simpleflatmapper.map.fieldmapper.ConstantSourceFieldMapperFactoryImpl.lookForAlternativeGetter(ConstantSourceFieldMapperFactoryImpl.java:272) at org.simpleflatmapper.map.fieldmapper.ConstantSourceFieldMapperFactoryImpl.getGetterFromSource(ConstantSourceFieldMapperFactoryImpl.java:249) at org.simpleflatmapper.map.fieldmapper.ConstantSourceFieldMapperFactoryImpl.newFieldMapper(ConstantSourceFieldMapperFactoryImpl.java:195) at org.simpleflatmapper.map.mapper.DefaultConstantSourceMapperBuilder.newFieldMapper(DefaultConstantSourceMapperBuilder.java:920) at org.simpleflatmapper.map.mapper.DefaultConstantSourceMapperBuilder$PropertyFieldMeta.targetFieldMapper(DefaultConstantSourceMapperBuilder.java:757) at org.simpleflatmapper.map.mapper.DefaultConstantSourceMapperBuilder.targetFieldMappers(DefaultConstantSourceMapperBuilder.java:649)...

If I use the normal .fetchResultSet() way everything works.

arnaudroger commented 5 years ago

Could you give me the column types in the dB and what the destination object type is? Is that just a j.u.Date or one of the Java time?

estebes commented 5 years ago

The column types are timestamptz (PostgreSQL) and the destination types are OffsetDateTime (the records and pojos are generated being generated by JOOQ).

arnaudroger commented 5 years ago

Thanks will have a look asap

estebes commented 5 years ago

Don't now if it helps but the sfm version im using is 6.0.8

arnaudroger commented 5 years ago

when using fetch().intoResultSet() jooq is creating a mock resultset with metadata return has
sqlType : 12 or VARCHAR getColumnClassName : "OffsetDateTime" getColumnTypeName : "timestamp with time zone"

the other result set sqlType : 93 or VARCHAR getColumnClassName : "Timestamp" getColumnTypeName : "timestamptz"

which we could use to deal with it

estebes commented 5 years ago

Is it something i can fix in my code or do I have to wait for you to fix it?

arnaudroger commented 5 years ago

yes should be able, when sqlType is 12 I'll double check out the columnclassname. I don't imagine your the same person as https://twitter.com/scott_shid/status/1060887524237864960 ?

arnaudroger commented 5 years ago

sorry meant it really needs to be fixed in the code, I should be able to push it out tonight. is there a reason you prefer using fetch().intoResultSet()?

estebes commented 5 years ago

No I don't have a twitter account. I prefer fetch().intoResultSet() because it handles everything for me. From the JOOQ docs:

Instead of operating on a JDBC ResultSet holding an open resource from your database, you can also let jOOQ's org.jooq.Result wrap itself in a java.sql.ResultSet. The advantage of this is that the so-created ResultSet has no open connection to the database. It is a completely in-memory ResultSet:

estebes commented 5 years ago

I found about this because HikariCP was complaining about connection leaks due to me using the ResultSet without closing it. So I found about this wrapping which would solve the problem entirely but that exception prevents me from using this solution. I am just using the other way and handling the result set closing and what not but it is not as nice or clean.

arnaudroger commented 5 years ago

6.0.9 is now available in maven central with the fix.

estebes commented 5 years ago

Thank you very much.

arnaudroger commented 5 years ago

np, could you just confirm it worked? when you can? Thanks for the report!

estebes commented 5 years ago

Can confirm it is working. If I find any problem during my testing in the next few days I'll let you know. Thanks again.