此过程涉及两个关键步骤:
以下代码示例可帮助说明这两个步骤:
EmployeeAccessBean aEmployee = new EmployeeAccessBean() aEmployee.setInit_employeeNo ("100"); aEmployee.setName ("IBM"); aEmployee.setAddress ("1150 Eglinton Ave, Toronto");
如果客户机程序在调用 commitCopyHelper() 之前在访问 bean 中设置了复制助手属性并执行获取操作,则访问 bean 将返回高速缓存中的数据而不是企业 bean 中的数据。通常,如果属性位于在高速缓存中,则访问 bean 将从高速缓存中获取该属性。但是,如果用户在一个还没有设置或检索的复制助手字段中执行获取操作,则将在企业 bean 中刷新高速缓存。
如果您打算调用返回枚举的 finder 并且从事务性作用域外部的客户机程序来调用它,则只有前五个结果将返回在枚举中。要返回所有结果,需要确保在事务中调用了 finder 方法。为此,可以从会话 bean 方法调用 finder 方法(其中,方法具有容器管理的事务属性),或者,可以在客户机中创建用户事务。例 如:
// Get the initial context java.util.Properties p = new java.util.Properties(); p.put(Context.PROVIDER_URL, "IIOP:///"); p.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory"); InitialContext initContext = new InitialContext(p); // Look up a transaction userTran = (UserTransaction)initContext.lookup("jta/usertransaction"); userTran.begin(); // Call the finder // Assume that employeeHome has already been found, and has a method defined findAll() Enumeration enum = employeeHome.findAll(); while (enum.hasMoreElements()) { // Process the enumeration } userTran.commit();