[SEAM] 請教:List对象从缓存中获到数据?

Mrpublic 2009-06-11
实体 Employee 与Salary 对象关系是一对多,
实体: Employee中

@OneToMany(mappedBy = "employee", fetch = FetchType.LAZY)
public Set<Salary> getBaseCheckSalary() {
return baseCheckSalary;
}

。。。

============================================================

在Action层中有一个方法如下:
@DataModelSelection("employeeList")
private Employee selectedEmployee;
@Factory("employeeList")
public void getEmployeeList() {
    employeeList = XXXBusniess.returnEmployeeList();
}

另一个方法是:給没有salary的employee新增salary,在新增结束时,会调用 this.getEmployeeList();
public void addSalary(){
.....
this.getEmployeeList();

}


============================================================
在busniess层中


public List<Employee> returnEmployeeList()
{
   List<Employee> tempList=entityManager.createQuery("from Employee e ").getResultList();
List<Employee> resultList= new ArrayList<Employee>();
  for(Employee emp: tempList){
    if(emp.getSalary==null||emp.getSalary.size()<0)
      resultList.add(emp);    
   return resultList;     
}
}

============================================================
现在出现一个问题就是在页面的那个新增按钮 有一个刷新 页面的动作 目的是要让
employeeList 重新数据。

<a4j: action="***.addSalary()" reRender="showResult"/>

可是页面上显示的还是原来的数据,除非把页面关闭重新运行,或者动手点击页面上的菜单上的刷新才会出现最新的数据?

=============================================================

这是为什么这样呢? 难道和实体中Employee 的fetch = FetchType.LAZY有关。。




怎样把缓存数据清空?,让红色部分直接从数据库中获得数据呀??
Mrpublic 2009-06-16
我们后来把上面红色部分改为

if(isSalaryEmpty(emp)

下面加了一个方法为:

private boolean isSalaryEmpty(Employee employee){
return
entityManager.createQuery("select emp.salary from Employee emp where e=:e").setParameter("e", employee).getResultList().isEmpty();
}

就是让其重新从数据中查一次,但这样写性能方法不太好呀 如果Employee员工数据为几十万条的话,那该有多慢

请圈内朋友帮帮看看吧 谢谢

ps:发现这儿不能删自己以前发的贴,故把以前过时的贴修改为名字与内容,呵呵,节省空间。。。。。
tyshan 2009-07-07
hi

对于帖子1)我建议优化一下hql

from Employee e where e.salary is null  or empty(e.salary)

对于贴子2)
select count(e.salary) from Employee e where e=:e;


开二级缓存,对性能肯定是有提高的,配置中加入二级缓存的支持,query加入hint.

Good luck

Tyshan
Mrpublic 2009-07-07
謝謝先,看看后試試不懂再向你請教哦
Mrpublic 2009-07-07
tyshan 写道
hi

对于帖子1)我建议优化一下hql

from Employee e where e.salary is null  or empty(e.salary)

对于贴子2)
select count(e.salary) from Employee e where e=:e;


开二级缓存,对性能肯定是有提高的,配置中加入二级缓存的支持,query加入hint.

Good luck

Tyshan



我對二級緩存不太懂,你這兒的二級緩存是開哪里的哦
andyhan 2009-07-07
Query Hints Example:

Query query = entityManager.createQuery("from User u").setHint("org.hibernate.readOnly", true);


Syntax: Query setHint(String hintName, Object value)


HintDescription
org.hibernate.timeoutQuery timeout in seconds ( eg. new Integer(10) )
org.hibernate.fetchSizeNumber of rows fetched by the JDBC driver per roundtrip ( eg. new Integer(50) )
org.hibernate.commentAdd a comment to the SQL query, useful for the DBA ( e.g. new String("fetch all orders in 1 statement") )
org.hibernate.cacheableWhether or not a query is cacheable ( eg. new Boolean(true) ), defaults to false
org.hibernate.cacheModeOverride the cache mode for this query ( eg. CacheMode.REFRESH )
org.hibernate.cacheRegionCache region of this query ( eg. new String("regionName") )
org.hibernate.readOnlyEntities retrieved by this query will be loaded in a read-only mode where Hibernate will never dirty-check them or make changes persistent ( eg. new Boolean(true) ), default to false
org.hibernate.flushModeFlush mode used for this query
org.hibernate.cacheModeCache mode used for this query




Mrpublic 2009-07-08
andyhan 写道
Query Hints Example:

Query query = entityManager.createQuery("from User u").setHint("org.hibernate.readOnly", true);


Syntax: Query setHint(String hintName, Object value)


HintDescription
org.hibernate.timeoutQuery timeout in seconds ( eg. new Integer(10) )
org.hibernate.fetchSizeNumber of rows fetched by the JDBC driver per roundtrip ( eg. new Integer(50) )
org.hibernate.commentAdd a comment to the SQL query, useful for the DBA ( e.g. new String("fetch all orders in 1 statement") )
org.hibernate.cacheableWhether or not a query is cacheable ( eg. new Boolean(true) ), defaults to false
org.hibernate.cacheModeOverride the cache mode for this query ( eg. CacheMode.REFRESH )
org.hibernate.cacheRegionCache region of this query ( eg. new String("regionName") )
org.hibernate.readOnlyEntities retrieved by this query will be loaded in a read-only mode where Hibernate will never dirty-check them or make changes persistent ( eg. new Boolean(true) ), default to false
org.hibernate.flushModeFlush mode used for this query
org.hibernate.cacheModeCache mode used for this query






thanks,
對它們的理解,應該多試試
Global site tag (gtag.js) - Google Analytics