Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Unable to implement update for existing source object to point to existing target object

Hi All

I have two tables

1. Employee (id, name, depid)
2. Department (depid, depname)

I have created employee and department dynamic types. I have a OneToMany relationship between the department and employee types.

I have to update the department of an employee. I am using the following code:

DynamicEntity emp = helper.newDynamicEntity(empBuilder.getType().getName());
emp.set("id", 147);
emp = (DynamicEntity) unitOfWork.readObject(emp);

DynamicEntity dep = helper.newDynamicEntity(depBuilder.getType().getName());
dep.set("depid", 1010);
dep = (DynamicEntity) unitOfWork.readObject(dep);

emp.set("empinfo.depinfo", dep);

However this does not update the depid for the employee row. The change is not present in the change set for the unit of work.

The unit of work that I have acquired from the session does not contain any objects before the readObject calls in the code above.

Can you please tell me what is wrong with the above code?

I have also tried to populate the list corresponding to the employees of department 1010, but even that does not work.

Is it mandatory to update the list or is it sufficient to modify the emp object alone?

When I use forceVersionUpdate for the emp object then, the session log does show UpdateQuery in the logs however no update query is executed against the database.
What is the reason for this behavior?

Happy New Year!

Rohit Banga
Member Technical Staff
Oracle India Private Limited
91 80 41085685

Back to the top