There is a problem with Hebernate result type conversion

1. When using hibernate"s sql query, the result of the database query is 1, and when it is returned to the backend, the result is transformed to 0.

2. The code is as follows:
database query code:
clipboard.png

eclipse:
clipboard.png

3.:
clipboard.png

4. Tried method:
1 when using a sql query, add |""to convert the result of count (1) to a string type.
2 when using a sql query, add |""to convert the result of to_chat () to a string type.
3 when eclipse accepts the results of the query, use the toString () method to convert the results to a string type.
4 when eclipse accepts the results of the query, use the (String) method to convert the results to a string type.

5. Needed help:
how to use hibernate to return integer results of queries in the database to chat, or convert results of type int to type String.

Dec.14,2021

Is the type queried by

count (*) bigdecimal? Then find out how to convert bigdecimal to string.

remove to_char from sql:

String danjuTotalSql = "count(*) from JS5_S12_SALES_....";
BigDecimal danjuTotal = (BigDecimal) em.createNativeQuery(danjuTotalSql).getSingleResult();
String danjuTotalStr = danjuTotal.toString();
Logger.info("danjuTotal=" + danjuTotalStr);

(BigDecimal) can be omitted depending on the situation.


database problem. Resolved.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be864b-318f8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be864b-318f8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?