【问题标题】:How to reload content from database view/ refresh entity?如何从数据库视图/刷新实体重新加载内容?
【发布时间】:2019-09-22 03:59:15
【问题描述】:

在我的 rapidclipse 4.0 项目中,我必须从数据库视图中读取数据,同时保存手动输入的数据。 然后应将读取的值包含到要保存的数据中。

我的问题是,这工作正常,只有一次/第一次保存。 如果我第二次保存,值不会更新。

在保存按钮单击事件中,我放置了以下代码:

private void cmdSave_buttonClick(final Button.ClickEvent event) {
    try {
        this.txtDmvTable.setValue("T_supplier");

        final int i = 1;
        VSuppliersNewId vsni = new VSuppliersNewId();
        vsni = new VSuppliersNewIdDAO().find(i);

        this.txtDmvCol00.setValue(vsni.getNewSupId().toString());

        this.fieldGroup.save();
    }
    catch(final Exception e) {
        e.printStackTrace();
        Notification.show("Do isch was falsch",
                e.getMessage(),
                Notification.Type.ERROR_MESSAGE);
    }
}

以下几行完全符合预期,但只有一次:

final int i = 1;
VSuppliersNewId vsni = new VSuppliersNewId();
vsni = new VSuppliersNewIdDAO().find(i);

this.txtDmvCol00.setValue(vsni.getNewSupId().toString());

视图VSuppliersNewId 将始终只返回一个最新值。
例如:

  • 我的视图返回表字段中的最大值。
  • 让我们假设在第一轮它返回号码237
  • 保存我的数据后,视图可能会返回238
  • 如果我在数据库中通过 sql 直接读取此内容,我将返回 238
  • 但是通过上面的代码它仍然保持237

我认为,必须刷新/重新加载来自数据库的整个代码链,但事实并非如此。

如何更改/增强我的代码以获得预期的结果?我做错了什么?

【问题讨论】:

  • 我也尝试设置持久性,xml 属性为无:<property name="xdev.queryCache.mode" value="NONE" />` without success. And I tried to set following entry in th entity: @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONE)` 和 @cacheable(false) 也没有成功。 ..

标签: java vaadin rapidclipse


【解决方案1】:

我自己找到了解决方案 我做了几个步骤。

1) 打开我的实体并设置 cacheable = false
2)打开persistence.xml并设置以下参数:

<property name="hibernate.cache.use_query_cache" value="false" />
<property name="xdev.queryCache.mode" value="ENABLE_SELECTIVE" />
<property name="hibernate.cache.use_second_level_cache" value="false" />

我使用以下代码来完成表格刷新:

 private void cmdSave_buttonClick(final Button.ClickEvent event) {
     try
     {
        this.txtDmvTable.setValue("T_supplier");

        final int i = 1;            
PersistenceUtils.getEntityManager(manOKMContacts.class).unwrap(SessionFactory.class);

        VSuppliersNewId vsni = new VSuppliersNewId();
        vsni = new VSuppliersNewIdDAO().find(i);

        this.txtDmvCol00.clear();
        this.txtDmvCol00.setValue(vsni.getNewSupId().toString());

        this.fieldGroup.save();

        this.table.getBeanContainerDataSource().removeAll();
        this.table.getBeanContainerDataSource().addAll(new OkmDbMetadataValueDAO().findAllContacts());
        this.table.getBeanContainerDataSource().refresh();

        this.table.setSortContainerPropertyId("DmvCol00");
        this.table.sort();

                     }
     catch(final Exception e)
     {
      Notification.show("Do isch was falsch", e.getMessage(), Notification.Type.ERROR_MESSAGE);
     }

}

希望这对其他人有所帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-27
    • 2011-04-26
    • 1970-01-01
    • 2014-07-01
    • 2019-11-15
    • 1970-01-01
    相关资源
    最近更新 更多