-->
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: Duplicate row creation!!
PostPosted: Thu Jun 27, 2013 12:06 am 
Newbie

Joined: Thu Jun 27, 2013 12:02 am
Posts: 1
Hi All,

I have the classes as below:

Student -

Code:
@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;

    private String fName;
    private String lName;
    private String mName;
   
    @OneToMany(cascade = CascadeType.ALL)
    @JoinColumn(name = "id")
    private Set<Phone> phones;




Phone -

Code:
@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int phoneId;


    private int phoneNumber;




So, my Phone table will have a foreign key referencing to Student table. Now if I do a create, it works fine with each row in the Student and Phone tables.

But if I do an update like say add a mname later on for the student, it creates another row in the phone table with the same data as the first row but now the second row will have reference to the phone table and first row foreign key is null.

I want to keep the above schema as is. I want the row to be created in the Phone table only when there is really a change. How can I achieve this? Please advice.

Thanks


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.