Я пытаюсь использовать Hibernate с JPA / EntityManager для выполнения операций с базой данных
Сейчас я получаю эту ошибку и понятия не имею, что это значит.
Раньше у меня был этот код, и он отлично работает.
public class JdbcProductDao extends Dao implements ProductDao {
/** Logger for this class and subclasses */
protected final Log logger = LogFactory.getLog(getClass());
public List<Product> getProductList() {
logger.info("Getting products!");
List<Product> products = getSimpleJdbcTemplate().query(
"select id, description, price from products",
new ProductMapper());
return products;
}
public void saveProduct(Product prod) {
logger.info("Saving product: " + prod.getDescription());
int count = getSimpleJdbcTemplate().update(
"update products set description = :description, price = :price where id = :id",
new MapSqlParameterSource().addValue("description", prod.getDescription())
.addValue("price", prod.getPrice())
.addValue("id", prod.getId()));
logger.info("Rows affected: " + count);
}
private static class ProductMapper implements ParameterizedRowMapper<Product> {
public Product mapRow(ResultSet rs, int rowNum) throws SQLException {
Product prod = new Product();
prod.setId(rs.getInt("id"));
prod.setDescription(rs.getString("description"));
prod.setPrice(new Double(rs.getDouble("price")));
return prod;
}
}
}
Но этот код с помощью EntityManager
public class JdbcProductDao implements ProductDao {
/** Logger for this class and subclasses */
//protected final Log logger = LogFactory.getLog(getClass());
@PersistenceContext()
private EntityManager entityManager;
public JdbcProductDao(){
}
public Product getReference(Product product){
return getEntityManager().getReference(product.getClass(),product.getId());
}
public void persist(Product product){
getEntityManager().persist(product);
}
public EntityManager getEntityManager(){
return entityManager;
}
public void setEntityManager(EntityManager entityManager){
this.entityManager = entityManager;
}
@SuppressWarnings("unchecked")
public List<Product> getProductList(){
return getEntityManager().createNativeQuery("select id, description, price from products").getResultList();
}
public void saveProduct(Product product){
getEntityManager().createNativeQuery("update products set description = " + product.getDescription() + " , price = " + product.getPrice() + " where id = " + product.getId());
}
private static class ProductMapper implements ParameterizedRowMapper<Product> {
public Product mapRow(ResultSet rs, int rowNum) throws SQLException {
Product prod = new Product();
prod.setId(rs.getInt("id"));
prod.setDescription(rs.getString("description"));
prod.setPrice(new Double(rs.getDouble("price")));
return prod;
}
}
}
Я получаю ошибку "java.lang.NumberFormatException: для входной строки:" description "
Кто-нибудь испытывал нечто подобное раньше?
Edit:
Трассировка стека ниже
java.lang.NumberFormatException: для входной строки: «описание»
java.lang.NumberFormatException.forInputString (NumberFormatException.java:48)
java.lang.Integer.parseInt (Integer.java:449)
java.lang.Integer.parseInt (Integer.java:499)
javax.el.ArrayELResolver.coerce (ArrayELResolver.java:153)
javax.el.ArrayELResolver.getValue (ArrayELResolver.java:45)
javax.el.CompositeELResolver.getValue (CompositeELResolver.java:54)
org.apache.el.parser.AstValue.getValue (AstValue.java:118)
org.apache.el.ValueExpressionImpl.getValue (ValueExpressionImpl.java:186)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate (PageContextImpl.java:935)
org.apache.jsp.WEB_002dINF.jsp.hello_jsp._jspx_meth_c_005fout_005f1 (hello_jsp.java:245)
org.apache.jsp.WEB_002dINF.jsp.hello_jsp._jspx_meth_c_005fforEach_005f0 (hello_jsp.java:210)
org.apache.jsp.WEB_002dINF.jsp.hello_jsp._jspService (hello_jsp.java:92)
org.apache.jasper.runtime.HttpJspBase.service (HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service (HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service (JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service (JspServlet.java:267)
javax.servlet.http.HttpServlet.service (HttpServlet.java:717)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel (InternalResourceView.java:236)
org.springframework.web.servlet.view.AbstractView.render (AbstractView.java:257)
org.springframework.web.servlet.DispatcherServlet.render (DispatcherServlet.java:1183)
org.springframework.web.servlet.DispatcherServlet.doDispatch (DispatcherServlet.java:902)
org.springframework.web.servlet.DispatcherServlet.doService (DispatcherServlet.java:807)
org.springframework.web.servlet.FrameworkServlet.processRequest (FrameworkServlet.java:571)
org.springframework.web.servlet.FrameworkServlet.doGet (FrameworkServlet.java:501)
javax.servlet.http.HttpServlet.service (HttpServlet.java:617)
javax.servlet.http.HttpServlet.service (HttpServlet.java:717)