I am facing problem with view object's calculated field.
Whenever I use values from viewObject at first time, its showing me the correct values, but whenever I apply Row r.refresh(Row.REFRESH_WITH_DB_FORGET_CHANGES) function on its row, the fields that are calculated field, becomes null.
Because of this issue, my application turn to NullPointerException. :(
Here in program, Gender is a calculted field, rest are EO fields.
public class Client_02
public static void main(String args) throws Exception
Hashtable env = new Hashtable(2);
Context context = new InitialContext(env);
ApplicationModuleHome home = (ApplicationModuleHome)context.lookup("com.training.bc4j.AMEmployeeDepartment");
try basing the transient view object attribute on a transient entity attribute. Note that refresh with db forget only sets the value back to the value originally read from the database. There is no new query issued and therefor transient attributes are not re-calculated. What you can try though is to set the transent attribute dependency to the attribute that it depends on so the attribute is refreshed when the dependent attribute changes.
Can you try defaulting the value for the transient attribute? Did you add the transient attr from VO editor? The NPE should be coming from your own code I guess. Adding NPE check is another alternative.
Another thing I observed is that AppModule should be tested/debugged with App Module tester and not with a main(). The AM instance is created by the framework.
it is just because, such situation is here at my original application.
I have a VO which is having all attributes from EO, and 1 attribute from different table, it is only in query using combination of foreign key of VO.
at that location gets problem for that attribute after row.refresh().
Just in case you haven't found a solution to get around the issue here is a workaround.
1. Create a new VO EmployeeView1. Remove all its attribute except the PK and GENDER.
2. Create a Required bind variable in EmployeeView1.Query section say bindEmployeeID.
3. Update the VO query where clause to use the bind variable. The query will now read "Select Employees.EMPLOYEE_ID, Employees.GENDER FROM EMPLOYEES Employees WHERE Employees.Employee_ID = :bindEmployeeID"
4. Goto EmployeeView VO editor. Remove the Gender attribute from default list i.e. keep the query to default, no SQL based attribute.
5. In ViewAccessors section add EmployeeView1 as accessor (as EmployeeView1_1) and edit the definition of this to make use of EmployeeView.EmployeeId for bind variable EmployeeView1.bindEmployeeID.
5. Now add a transient attribute say "GenderTransient" as String and select the default value of it as expression as EmployeeView1_1.first().getAttribute("GENDER")