Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 365931 - @JoinColumn(name="FK_DEPT",insertable = false, updatable = true) causes INSERT statement to include this data value that it is associated with
Summary: @JoinColumn(name="FK_DEPT",insertable = false, updatable = true) causes INSER...
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 blocker (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-07 12:15 EST by Stephen DiMilla CLA
Modified: 2022-06-09 10:31 EDT (History)
5 users (show)

See Also:


Attachments
Proposed changes (30.77 KB, patch)
2013-02-11 14:00 EST, Guy Pelletier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stephen DiMilla CLA 2011-12-07 12:15:42 EST
Build Identifier: eclipselink-2.3.0.v20110604-r9504

Using the following 2 entities:
---------------------
@Cacheable(false)
@Entity
@Table(name="EMPLOYEE")
public class Employee4 implements java.io.Serializable {

    private int	     	     id;
    private String	     firstName;
    private String	     lastName;
    private Date	     hireDate;
    private float	     salary;
    private Department       department;

    public Employee4() {
    }

    public Employee4(int id, String firstName, String lastName)
    {
        	this.id = id;
        	this.firstName = firstName;
        	this.lastName = lastName;
    }    
    ...    
    @ManyToOne
    @JoinColumn(name="FK_DEPT",insertable = false, updatable = true)
    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 = false, updatable = true
            Employee4 empRef4 = new Employee4(8, "Thomas", "Brady");
            empRef4.setDepartment(new Department(1, "Marketing"));
            em.persist(empRef4);
            em.flush();
            et.commit();

-------------------------
I get the following output:

[javatest.batch] [EL Fine]: 2011-12-07 10:47:33.92--ClientSession(1711465251)--Connection(1192380230)--Thread(Thread[main,5,main])--INSERT INTO EMPLOYEE (ID, HIREDATE, LASTNAME, SALARY, FK_DEPT) VALUES (?, ?, ?, ?, ?)
[javatest.batch] 	bind => [8, null, Brady, 0.0, 1]

Notice that the FK_DEPT value is being included.

If I were to change the @JOINCOLUMN statement to:
    @JoinColumn(name="FK_DEPT",insertable = false, updatable = false)

Then the output would be:
[javatest.batch] [EL Fine]: 2011-12-07 10:47:33.92--ClientSession(1711465251)--Connection(1192380230)--Thread(Thread[main,5,main])--INSERT INTO EMPLOYEE (ID, HIREDATE, LASTNAME, SALARY) VALUES (?, ?, ?, ?)
[javatest.batch] 	bind => [8, null, Brady, 0.0]

 


Reproducible: Always
Comment 1 Tom Ware CLA 2012-04-05 11:01:14 EDT
Updating target milestone.
Comment 2 Guy Pelletier CLA 2013-02-11 14:00:12 EST
Created attachment 226868 [details]
Proposed changes
Comment 3 Guy Pelletier CLA 2013-02-11 14:38:33 EST
Changes have been submitted.

Reviewed: Gordon Yorke

New test (testNonInsertableAndUpdatable121Mappings) added to EntityManagerTestSuite.java
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:31:35 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink