Save changes to database vaadin(保存对数据库 vaadin 的更改)
问题描述
我有一个应用程序,它有一个表格,当您单击表格中的一个项目时,它会使用其数据(FieldGroup)填充一组文本字段,然后您可以选择保存更改我是想知道如何保存用户对我的 postgres 数据库所做的更改.我正在为这个应用程序使用 vaadin 和 hibernate.到目前为止,我已经尝试过
I have an application which has a table and when you click on an item in the table it fills in a group of textfields with its data (FieldGroup), and then you have the option of saving the changes I was wondering how would I save the changes the user makes to my postgres database. I am using vaadin and hibernate for this application. So far I have tried to do
editorField.commit() // after the user clicks the save button
我试过了
editorField.commit()
hbsession.persist(editorField) //hbsession is the name of my Session
我也试过了
editorField.commit();
hbsession.save(editorField);
最后两个给我以下错误
Caused by: org.hibernate.SessionException: Session is closed!
推荐答案
我已经弄清楚如何对数据库进行更改,这里有一些代码来演示:
I have figured out how to make changes to the database here is some code to demonstrate:
try {
/** define the session and begin it **/
hbsession = HibernateUtil.getSessionFactory().getCurrentSession();
hbsession.beginTransaction();
/** table is the name of the Bean class linked to the corresponding SQL table **/
String query = "UPDATE table SET name = " + textfield.getValue();
/** Run the string as an SQL query **/
Query q = hbsession.createQuery(query);
q.executeUpdate(); /** This command saves changes or deletes a entry in table **/
hbsession.getTransaction().commit();
} catch (RuntimeException rex) {
hbsession.getTransaction().rollback();
throw rex;
}
这篇关于保存对数据库 vaadin 的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:保存对数据库 vaadin 的更改


基础教程推荐
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01