-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: how to update child foreign column when parent is deleted
PostPosted: Tue Mar 05, 2013 5:02 am 
Newbie

Joined: Tue Mar 05, 2013 4:56 am
Posts: 1
my requirement is when i delete the parent ,child should not be deleted but instead of deleting child,one of the child column department_ID which is foreign key must be update with some value , say one department(Parent Table) contains many employee and employee(child Table) table have Department_ID as a foreign key column .The problem i m facing when i delete the parent table nothing is reflected on child cause i have make updatable=false if i will make it true then on deleting parent ,child column is set null or if i update the parent then also child Department_Id column set to null which is violating the requirement so that's why i make it false .I don't want child to be update when the parent make any changes only changes should reflected on delete operation ,only on one foreign column. Please help me what should i do? thanks
ParentTable(Department) code
Code:

  @Id
  @Column(name = "DEPARTMENT_ID")
  private String departmentId;

  @OneToMany(fetch = FetchType.EAGER)
  @JoinColumn(name = "DEPARTMENT_ID",insertable=false,updatable=false)
  Collection<Employee> employeeList;


Child Table(employee)code
Code:
    @Id
    @Column(name = "EMPLOYEE_NUMBER")
    private int employeeNumber;
    @Column(name = "FIRST_NAME")
    private String firstName;
    @Column(name = "LAST_NAME")
    private String lastName;

    @Column(name = "DEPARTMENT_ID")
    private String departmentId;


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.