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
438 stars 76 forks source link

Inserting rows with java.util.UUID columns/primary keys stored as binary(16) in MS SQL Server #721

Open coffeeandicecream opened 4 years ago

coffeeandicecream commented 4 years ago

I'm using the Spring JDBC version of SFM 8.2.3 and I'm having the following issues with inserting rows containing UUIDs that need to be converted to binary(16). I figured out how to fix the reads with a getter but the writes/inserts have been tricky to figure out. I resorted to manual queries but would really like to use the crud and auto-mapping functionality of this library.

Do I need to have a custom setter to handle this write conversion?

Thanks in advance.

JdbcTemplateCrud<T, K> crudDao = JdbcTemplateMapperFactory .newInstance() .addKeys("id") .addGetterForType( UUID.class, (rs, uuidColIndex) -> { return UUIDUtils.getUUIDFromByteArray(rs.getBytes(uuidColIndex)); }) .crud(entityType, keyType) .to(namedParamJdbcTemplate.getJdbcTemplate(), table);

arnaudroger commented 4 years ago

Thinks I'll have a look