-->
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: when removing from one to many collection ... help
PostPosted: Thu Aug 28, 2008 9:38 am 
Newbie

Joined: Wed Aug 13, 2008 11:22 am
Posts: 4
hi guys

i have a question: Following scenario:

table1: Person (id , name) => pk: id
table2: Person_Email(id, email) => pk: id, email with id also being a fk to person

my entities are like this

Code:
@Entity
@Table(name="person")
public class Person implements Serializable{

   private static final long serialVersionUID = 1L;

   @Id
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "person_seq")
   @SequenceGenerator(name = "person_seq", sequenceName = "person_seq", allocationSize = 1)
   @Column(name="id")
   private int id;
   
   @Column(name="name", length=40)
   private String name;

   @OneToMany(cascade=CascadeType.ALL)
   @JoinColumn(name="id")
   private List<PersonEmail> emails;
}


and the other one

Code:
@Entity
@Table(name="person_email")
public class PersonEmail implements Serializable{

   private static final long serialVersionUID = 1L;

   @Id
   private Pk pk;

}


Pk is a composite primary key class: very simple also:

Code:
@Embeddable
public class Pk implements Serializable{

   private static final long serialVersionUID = 1L;

   @Column(name="id")
   private int id;
   
   @Column(name="email")
   private String email;
}



now everything works fine... i can create a new Person object ... add email addresses save them, update them but then ...

when i try to delete an email address from the collection hibernate for some reason tries to just "remove the link" by updating the id of person_email to null... which is of course not possible since its part of the primary key

here the query that is being issued:

Hibernate:
/* delete one-to-many row com.domain.Person.emails */ update
person_email
set
id=null
where
id=?
and email=?
and id=?

here is the error

java.sql.BatchUpdateException: ORA-01407: cannot update ("MYDB"."PERSON_EMAIL"."ID") to NULL

now the question... is there a way to tell hibernate to force a delete... not an update... ?

thank you


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.