使用数据库中的新数据更新应用程序的问题 [英] problem with updating application with new data from database

查看:170
本文介绍了使用数据库中的新数据更新应用程序的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序从数据库中提取数据,然后显示它。现在我遇到的问题是,每小时我想对数据库中的数据进行更新;这是由一个单独的应用程序,这一切工作正常。但是,一旦发生这种情况,并且用户刷新其网页,则不会显示新数据。

I have a web application that pulls data from the database then displays it. Now the problem I'm having is that every hour I want to do updates on the data in the database; this is done by a separate app, this all works fine. However, once this has happened and the user refreshes their web page, the new data isn't being displayed.

我希望这有意义。

我会从应用程序中提供一些代码,以便您更好地看到它。

I'll provide some code from the app so that you see it better.

我的网络应用程序是使用java我有一个持久化单元,它将类映射到数据库中的表。我使用wicket将我的组件添加到我的html。

My web app is written in netbeans using java and I have a persistence unit that is mapping classes to tables in the database. I'm using wicket to add my components to my html.

// Java Wicket代码

// Java Wicket code

ApplicationSettings apset = new ApplicationSettingsDAO().getApplicationSettings();    
this.add(new Label("lblGameTime", "" + apset.getGameTimeDays()));

// Wicket HTML代码

// Wicket html code

Date : day <span wicket:id="lblGameTime">generated date</span>

// DAO应用程序设置,它从db获取设置对象并将其返回到上面的Java Wicket代码

// DAO application settings which gets the settings object from the db and returns it to the Java Wicket code above

public ApplicationSettings getApplicationSettings() {

    ApplicationSettings settings;

    try {
     Query q = manager.createQuery("select s from ApplicationSettings s where s.setting = :setting");
     q.setParameter("setting", "setting");
     settings = (ApplicationSettings) q.getSingleResult();
  } catch (NoResultException e) {
     ApplicationSettings newSetting = new ApplicationSettings();
     return newSetting;
  }
     return settings;

}

// ApplicationSettings

//ApplicationSettings is just the class.

//每小时代码在另一个应用程序中运行,并且更新db

//Hourly code ran in another app that works and does update db

Query query6 = manager.createQuery("select s from ApplicationSettings s where s.setting = :setting");
    query6.setParameter("setting", "setting");
    ApplicationSettings apset = (ApplicationSettings) query6.getSingleResult();
    apset.setGameTimeDays(apset.getGameTimeDays() + 1);
    save(apset);

现在,当用户再次加载页面时,我会期望 gameTimeDays 将是正确的,因为页面将再次从数据库获取数据,因为它会调用上面的 java wicket代码。但是值不改变。在页面上显示的值是更新之前的旧陈旧值。无论发生多少更新,此值仍然是旧值。然而,如果我在tomcat服务器中重新部署或重新启动模块,那么该值在那个时刻是正确的。

Now when the user loads the page again I'd expect that the gameTimeDays would be correct as the page would get the data from the db again because it'd call the java wicket code above. BUT the value does not change. The value that shows up on the page is the old stale value before the update. No matter how many updates take place this value is still the old value. HOWEVER if I do a redeploy or restart the module in the tomcat server, the value is then correct for that moment in time.

我缺少什么,这是一个小问题,答案似乎暗示我。

What am I missing, this is a tiny problem that the answer seems to be alluding me.

值似乎存储在内存中,直到服务器被重新部署或某事。我不知道很多关于java的内部工作知道这个。

The value seems to be stored in memory till the server is redeployed or something. I dont know alot about the inner workings of java to know about this.

确定我希望我提供足够的信息,帮助我解决我的困境。

Ok I hope I provided enough info for someone to help me with my dilemma.

感谢任何帮助。

编辑:持久性库是TopLink Essentials

persistence library is TopLink Essentials

推荐答案

听起来像是你的数据被你使用的持久化机制缓存(你不公开它的细节)。这不是Java的一个特性,而是特定持久性框架的特性,例如。 Hibernate。

Sounds like your data is being cached by the persistence mechanism you use (about which you don't disclose details). This is not a feature of Java, but that of specific persistence frameworks like e.g. Hibernate.

如果你让我们更多地了解你的持久化提供者,我们可以给出更具体的建议。

If you let us know more about your persistence provider, we may be able to give more concrete advice.

这篇关于使用数据库中的新数据更新应用程序的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆