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

Problem with ResultSetExtractorImpl #600

Closed AntonKuzValid closed 5 years ago

AntonKuzValid commented 5 years ago

I'm working with hive using ext driver - org.apache.hive:hive-jdbc:1.1.0-cdh5.16.0, i'm trying next ```

hiveTemplate.query("""SELECT` t2.set_id id, t2.oper_date oper_date, t2.slip_info.name name, t2.slip_info.surname surname, t2.slip_info.last_card_digits last_card_digits, t1.barcode barcodes_val
                from tobacco_barcodes t1 JOIN operkass_od t2 on t1.barcode=t2.barcode where t2.oper_day>=:startDate""",
                    getParams("startDate" to startDate), mapper)

val mapper = = JdbcTemplateMapperFactory.newInstance()
            .ignorePropertyNotFound()
            .addKeys("id", "barcodes_val")
            .newResultSetExtractor<OperationKassFromHive>(OperationKassFromHive::class.java)!!

data class OperationKassFromHive(
        var id: Int? = null,
        var operDate: LocalDateTime? = null,
        var name: String? = null,
        var surname: String? = null,
        var lastCardDigits: String? = null,
        var barcodes: MutableList<String>? = null
)

And finally i get list wich contains some no unique entries with the same id and differnt barcode and some enties with several barcodes. I expected to get only entries with unique ids

PS: i am using implementation group: 'org.simpleflatmapper', name: 'sfm-springjdbc', version: '6.0.11'

arnaudroger commented 5 years ago

The group by id at the root level is made by id change detection which mean the query needs to be ordered by id at least

If you don’t want to add on order by at the query than instead of mapping to T create a mapper to a List of T then the order should not matter but it’s less efficient - also I never really tested that

arnaudroger commented 5 years ago

@AntonKuzValid did that answer your question? if not please reopen the ticket.