我有附加说明的方法,通过计算参数接收一个实体。 在这种方法中,我试图确定三个变数:
@Inject EntityDao entityDao;
@Asynchronous
public Future<String> doSomething (MyEntity p_myEntity) {
MyEntity myEntity = entityDao.merge(p_myEntity); // change from detached to attached
// em.contains(myEntity) returns true
myEntity.setName("Joe 1"); // newer set in database
// A System.out.println(myEntity.getName()) does say "Joe 1"
try {
Thread.sleep(20*1000);
} catch () ...etc
myEntity.setName("Joe 2"); // newer set in database
// A System.out.println(myEntity.getName()) does say "Joe 2"
try {
Thread.sleep(20*1000);
} catch () ...etc
myEntity.setName("Joe 3"); // only one set in database
return new AsyncResult<>("done");
}
Edit: So thanks to PedroKowalski I have a better understanding of the problem and I will reformulate.
在采用上述方法期间,我有两种方式检查是否真心改变:
- During the sleep() I check the database if the name value is changed
- On a webpage the list of MyEntity objects are displayed (with the names), this list is being updated every 2 seconds.
上述两种方法都表明,数据库中“联合1”和“联合2”的数值较新。 只有在采用Something(Something)方法之后,最后的名称(Joe 3)才被列入数据库。
因此,我的问题是:为什么没有将“联合1”和“联合2”的数值列入数据库,而只有最后价值才列入数据库?