-->
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: Cascade delete issue
PostPosted: Fri Dec 03, 2010 11:51 am 
Newbie

Joined: Thu Jul 27, 2006 12:55 pm
Posts: 5
Hello,

I have to manage the following classes through JPA API manage by org.hibernate.ejb.HibernatePersistence [ version 3.5.1]:

Code:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="disc",discriminatorType=DiscriminatorType.STRING)
public abstract class Root {
   @Id
   @GeneratedValue(strategy=GenerationType.IDENTITY)
   private Integer id;
}
[...]
@Entity
@DiscriminatorValue("A")
public class A extends Root {

   @Entity
   public static class B {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Integer id;

      @Basic
      private String name;
   }

   private String name;

   @OneToMany(orphanRemoval = true, cascade = CascadeType.ALL)
    @JoinColumn(name="fk_a", nullable=false)
   private Set<B> bs;
}
[...]


As a summary, A extends Root; A contains an inner class B; A has an unidirectional one-to-many relationship with B. Obviously, I did not mention all getters/setters.

I want to purge all A objects with the following code:

Code:
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.createQuery("delete from A").executeUpdate();
em.getTransaction().commit();


And Hibernate pushed the folling orders to the DB (PG9):

Code:
Hibernate: insert into HT_A select a0_.id as id from cde.A a0_ inner join cde.Root a0_1_ on a0_.id=a0_1_.id
Hibernate: delete from cde.A where (id) IN (select id from HT_A)
0    [main] ERROR org.hibernate.util.JDBCExceptionReporter  - ERREUR: UPDATE ou DELETE sur la table « a » viole la contrainte de clé étrangère
« fkf89f26e3276c » de la table « a$b »
  Détail : La clé (id)=(1) est toujours référencée à partir de la table « a$b ».


So my first question is why Hibernate does not care about the B instances related to A objects?

Second one is why Hibernate needs to create a temp table to store the ids to delete?

Regards


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.