try:
criteria.add(Restrictions.sqlRestriction("FORMAT(price,2) = FORMAT(discountPrice,2)"));
by using sqlRestriction() you can insert literal SQL fragments right into query
题
Here I have 2 value example price and discountPrice. When I using mysql
select price, discountPrice from stockItem where price = discountPrice;
I found no record.
After I changed to
select price, discountPrice from stockItem where FORMAT(price,2) = FORMAT(discountPrice,2);
I able to query the record out.
May I know in hibernate how to write Detachedcriteria in 2 decimal point?
Here the Current Code:
DetachedCriteria criteria = DetachedCriteria.forClass(StockItem.class);
criteria.add(Restrictions.eqProperty("price", "discountPrice"));
return getHibernateTemplate().findByCriteria(criteria);
Is there a way to write?
In mysql We saw it is 10.70. I only suspect the number actual number is 10.700000000000001. Is there a way to identify this?
Thank
解决方案
try:
criteria.add(Restrictions.sqlRestriction("FORMAT(price,2) = FORMAT(discountPrice,2)"));
by using sqlRestriction() you can insert literal SQL fragments right into query