我在我的 JSP 中添加了以下代码,并在将实体保存到 db 时遇到了一些异常。
$('.validateWeight').click(function(event) {
var id = event.target.id;
var value;
$("#saveValue").val("");
if(id == "saveAndContinue"){
var el = document.getElementById('saveValue');
el.value = 1;
//<c:set var="saveValue" scope="page" value="1"/>;
}else if(id=="saveAndClose"){
var el = document.getElementById('saveValue');
el.value = 2;
//<c:set var="saveValue" scope="page" value="2"/>;
}
和
在我的Java Action Class中,我添加了 getter 和 setter
在需要的情况下,我将值设置为 1 和 2,但是在保存实体时,我不知道“ NAN
”值来自何处以及来自何处,并且我遇到了保存调用的问题。
例外:
org.springframework.dao.TransientDataAccessResourceException: Hibernate operation: could not update: [com.hk.domain.inventory.GrnLineItem#100]; SQL [update person set age=?, no_of_children=?, address_line_1=?, address_line_2=?, mrp=?, state=?, city=?, pincode=?, weight=? where id=?]; 'NaN' is not a valid numeric or approximate numeric value; nested exception is java.sql.SQLException: 'NaN' is not a valid numeric or approximate numeric value
org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:107)
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
org.springframework.orm.hibernate3.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:424)
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:410)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:881)
com.hk.impl.dao.BaseDaoImpl.resetHibernateAfterWrite(BaseDaoImpl.java:247)
和
java.sql.SQLException: 'NaN' is not a valid numeric or approximate numeric value
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
com.mysql.jdbc.PreparedStatement.setDouble(PreparedStatement.java:3572)
org.apache.commons.dbcp.DelegatingPreparedStatement.setDouble(DelegatingPreparedStatement.java:129)
org.apache.commons.dbcp.DelegatingPreparedStatement.setDouble(DelegatingPreparedStatement.java:129)
org.apache.commons.dbcp.DelegatingPreparedStatement.setDouble(DelegatingPreparedStatement.java:129)
org.hibernate.type.DoubleType.set(DoubleType.java:60)
org.hibernate.type.NullableType.nullSafeSet(NullableType.java:154)
org.hibernate.type.NullableType.nullSafeSet(NullableType.java:131)
org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2025)
org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2399)
org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2335)
org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2635)
org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:115)
org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
org.springframework.orm.hibernate3.HibernateTemplate$28.doInHibernate(HibernateTemplate.java:883)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:881)
com.hk.impl.dao.BaseDaoImpl.resetHibernateAfterWrite(BaseDaoImpl.java:247)
com.hk.impl.dao.BaseDaoImpl.save(BaseDaoImpl.java:237)