| Summary: |
@JoinColumn(name="FK_DEPT",insertable = true, updatable = false) causes UPDATE statement to include this data value that it is associated with |
| Product: |
z_Archived
|
Reporter: |
Stephen DiMilla <stephen.dimilla> |
| Component: |
Eclipselink | Assignee: |
Nobody - feel free to take it <nobody> |
| Status: |
RESOLVED
FIXED
|
QA Contact: |
|
| Severity: |
blocker
|
|
|
| Priority: |
P3
|
CC: |
eclipselink.orm-inbox, guy.pelletier, lance.andersen, stephen.dimilla, tom.ware
|
| Version: |
unspecified | |
|
| Target Milestone: |
--- | |
|
| Hardware: |
Macintosh | |
|
| OS: |
Mac OS X - Carbon (unsup.) | |
|
| Whiteboard: |
|
| Attachments: |
|
Build Identifier: eclipselink-2.3.0.v20110604-r9504 Using the following 2 entities: --------------------- @Cacheable(false) @Entity @Table(name="EMPLOYEE") public class Employee3 implements java.io.Serializable { private int id; private String firstName; private String lastName; private Date hireDate; private float salary; private Department department; public Employee3() { } public Employee3(int id, String firstName, String lastName) { this.id = id; this.firstName = firstName; this.lastName = lastName; } ... @ManyToOne @JoinColumn(name="FK_DEPT",insertable = true, updatable = false) public Department getDepartment() { return department; } public void setDepartment(Department department) { this.department = department; } --------------------- @Cacheable(false) @Entity @Table(name="DEPARTMENT") public class Department implements java.io.Serializable { // Instance variables private int id; private String name; public Department() { } public Department(int id, String name) { this.id = id; this.name = name; } --------------------- --------------------- And the following client code: et.begin(); //insertable = true, updatable = false Employee3 empRef3 = new Employee3(7, "Paul", "Jones"); empRef3.setDepartment(new Department(1, "Marketing")); em.persist(empRef3); em.flush(); et.commit(); et.begin(); em.clear(); Employee3 emp3 = getEntityManager().find(Employee3.class, 7); System.out.println("Name:" + emp3.getFirstName() + " " + emp3.getLastName()); System.out.println("Department:" + emp3.getDepartment().getId()+", "+emp3.getDepartment().getName()); System.out.println("set department to:"+deptRef[1].getId()+", "+deptRef[1].getName()); emp3.setDepartment(deptRef[1]); getEntityManager().merge(emp3); getEntityManager().flush(); getEntityManager().clear(); System.out.println("find employee3 again"); emp3 = getEntityManager().find(Employee3.class, 7); System.out.println("Name:" + emp3.getFirstName() + " " + emp3.getLastName()); dept = emp3.getDepartment(); if (dept != null && dept.getName().equals(deptRef[0].getName())) { System.out.println("Received expected department:" + dept.getName()); } else { pass = false; System.out.println("Expected department:" + deptRef[0].getName() + ", actual:" + dept.getName()); } ------------------------- I get the following output: [javatest.batch] [EL Fine]: 2011-12-07 12:29:42.657--ClientSession(875010279)--Connection(1864311781)--Thread(Thread[main,5,main])--SELECT ID, FIRSTNAME, HIREDATE, LASTNAME, SALARY, FK_DEPT FROM EMPLOYEE WHERE (ID = ?) [javatest.batch] bind => [7] [javatest.batch] [EL Fine]: 2011-12-07 12:29:42.659--ClientSession(875010279)--Connection(1864311781)--Thread(Thread[main,5,main])--SELECT ID, NAME FROM DEPARTMENT WHERE (ID = ?) [javatest.batch] bind => [1] Name:Paul Jones Department:1, Marketing set department to:2, Administration [javatest.batch] [EL Fine]: 2011-12-07 12:29:42.66--ClientSession(875010279)--Connection(1864311781)--Thread(Thread[main,5,main])--SELECT ID, NAME FROM DEPARTMENT WHERE (ID = ?) [javatest.batch] bind => [2] [javatest.batch] [EL Fine]: 2011-12-07 12:29:42.663--ClientSession(875010279)--Connection(1864311781)--Thread(Thread[main,5,main])--UPDATE EMPLOYEE SET FK_DEPT = ? WHERE (ID = ?) [javatest.batch] bind => [2, 7] find employee3 again [javatest.batch] [EL Fine]: 2011-12-07 12:29:42.666--ClientSession(875010279)--Connection(1864311781)--Thread(Thread[main,5,main])--SELECT ID, FIRSTNAME, HIREDATE, LASTNAME, SALARY, FK_DEPT FROM EMPLOYEE WHERE (ID = ?) [javatest.batch] bind => [7] [javatest.batch] [EL Fine]: 2011-12-07 12:29:42.668--ClientSession(875010279)--Connection(1864311781)--Thread(Thread[main,5,main])--SELECT ID, NAME FROM DEPARTMENT WHERE (ID = ?) [javatest.batch] bind => [2] Name:Paul Jones Expected department:Marketing, actual:Administration Notice that the FK_DEPT value is being included in the UPDATE statement (when it should not due to updateable="false") and that the final find (SELECT) done in the client code is returning the updated department instead of the original department. Reproducible: Always