简体   繁体   中英

JPA Repository method List<Integer> returns result as List<BigDecimal> why?

I have next method in JPA Repository kartDao:

@Query(value = "select t.k_lsk_id from SCOTT.KART t ", nativeQuery = true)
List<Integer> findAllKlskId();

When I try to fetch it using:

List<Integer> someLst = new ArrayList<Integer>();
someLst.add(12); // my Integer value
someLst.addAll(kartDao.findAllKlskId());

I see in debugger that someList contains both Integer and BigDecimal types:

在此处输入图片说明

But how it happens? My someList is List type!! Can't understand, help me))

upd1 In Oracle database the k_lsk_id type is Number:

在此处输入图片说明

The culprit is this line of code I think. It tries to convert the result of the query execution. If it fails to find a converter it just returns the original unconverted result.

The converter used is essentially a DefaultConversionService which doesn't support any convertions from BigDecimal .

UPDATE: I looked a little more into this, and it seems that the problem is not so much that the conversion service can't convert BigDecimal , but that the requested target type is simply List .

I opened an issue and will look into it.

Number return decimal value form the DB side.

you should have to change the number to Integer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM