0
我使用Primefaces 3.5對象+ hibernate的4.2.0更新在休眠
我使用primefaces的cell editing table和想更新我的產品表我的數據庫,當我點擊一個字段,改變我的表值。然而,我只發現這樣的休眠簡單屬性的更新方法是這樣的:
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
String jpqlUpdate = "update Customer set name = :newName where name = :oldName"
int updatedEntities = entityManager.createQuery(jpqlUpdate)
.setParameter("newName", newName)
.setParameter("oldName", oldName)
.executeUpdate();
entityManager.getTransaction().commit();
entityManager.close();
如何更新整個對象,在休眠?
你可以看到[Hibernate Annotations](http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/) – navand 2013-04-20 16:02:10
還有一種可能的方式來使用簡單的'update '聲明? – maximus 2013-04-20 16:09:39
你想要的東西是這樣的:Transaction transaction = null; String sqlQuery =「UPDATE YourTable SET yourColumn1 =」+ yourValue1 +「,yourColumn2 ='」+ yourValue2 +''WHERE someCondition「; SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.getCurrentSession(); transaction = session.beginTransaction(); SQLQuery query = session.createSQLQuery(sqlQuery); result = query.executeUpdate();transaction.commit(); – navand 2013-04-20 16:12:53