【问题标题】:how to commit updated data (vaadin jpacontainer)如何提交更新的数据(vaadin jpacontainer)
【发布时间】:2013-02-21 09:07:51
【问题描述】:

我是 vaadin jpacontainer 的新手。我正在使用 vaadin jpacontainer agpl-3.0-2.10。

我制作了一个 Person 类,我的应用程序类如下所示:

EntityManager em = JPAContainerFactory.createEntityManagerForPersistenceUnit("book-examples");

JPAContainer<Person> persons = JPAContainerFactory.make(Person.class, "book-examples");
persons.setReadOnly(false);

persons.addEntity(new Person("Marie-Louise Meilleur", 117));
persons.addEntity(new Person("Sarah Knauss", 122));

Table personTable = new Table("person",persons);
personTable.setReadOnly(false);

persons.getItem(1L).getEntity().setName("Me");
persons.commit();
personTable.commit();
layout.addComponent(personTable);

当我运行应用程序时,结果如我所愿:第一个项目的名称是“我”。但是当我检查数据库时,第一个项目的名称是“Marie-Louise Meil​​leur”。为什么commit方法没有改变数据库?

【问题讨论】:

  • 啊,方法不对。应该是persons.getItem(1L).getItemProperty("name").setValue("me");
  • 您也可以回答自己的问题,而不仅仅是将解决方案添加为评论。这不被认为是不好的做法。见:blog.stackoverflow.com/2011/07/…

标签: jpa vaadin


【解决方案1】:

啊,方法不对。应该是persons.getItem(1L).getItemProperty("name").setValue("me");

【讨论】:

    猜你喜欢
    • 2012-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-09
    相关资源
    最近更新 更多