-->
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: ON DELETE CASCADE constraint not created
PostPosted: Tue Aug 31, 2010 9:27 am 
Newbie

Joined: Tue Aug 31, 2010 9:07 am
Posts: 1
Hi,

I currently facing a problem creating a foreign key with ON DELETE CASCADE attribute.

Here are my entities :

- One main entity BoxWcsKlEntityBean, which is linked to an abstract entity AbstractBoxDdWcsKlEntityBean, this second one extends from another abstract mappedsuperclass AbstractBoxModuleWcsKlEntityBean. And after all, one class BoxWcsDdEntityBean which extends from AbstractBoxDdWcsKlEntityBean :
Code:
@Entity(name = BoxWcsKlEntityBean.ENTITY_NAME)
@Table(name = BoxWcsKlEntityBean.TABLE_NAME)
public class BoxWcsKlEntityBean {
...
  @OneToOne(mappedBy = "box", cascade = { CascadeType.PERSIST, CascadeType.REMOVE }, fetch = FetchType.LAZY, optional = true)
  public AbstractBoxDdWcsKlEntityBean getBoxDd() {
    return boxDd;
  }
...
}


@Entity(name = AbstractBoxDdWcsKlEntityBean.ENTITY_NAME)
@Table(name = AbstractBoxDdWcsKlEntityBean.TABLE_NAME)
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class AbstractBoxDdWcsKlEntityBean
    extends AbstractBoxModuleWcsKlEntityBean {
...
}


@MappedSuperclass
public abstract class AbstractBoxModuleWcsKlEntityBean {
...
   private BoxWcsKlEntityBean box;

   @OneToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "ID_BOX", nullable = false)
   @OnDelete(action = OnDeleteAction.CASCADE)
   public BoxWcsKlEntityBean getBox() {
       return box;
   }
}


@Entity(name = BoxWcsDdEntityBean.ENTITY_NAME)
@Table(name = BoxWcsDdEntityBean.TABLE_NAME)
public class BoxWcsDdEntityBean
    extends AbstractBoxDdWcsKlEntityBean {
...

}


In the MappedSuperclass, I have notified a @OnDelete tag in order to create a ON DELETE CASCADE contraint, so that when I delete a BoxWcsKlEntityBean, database will delete in cascade the BoxWcsDdEntityBean associated to it (I want database to do it, not hibernate !).

So as inheritance is TABLE_PER_CLASS, two tables are created : one for entity BoxWcsKlEntityBean and the other one for BoxWcsDdEntityBean. The problem is that foreign key is well created in table BoxWcsDdEntityBean, but not with the ON DELETE CASCADE attribute.....

I tried to override the getBox() method in BoxWcsDdEntityBean, like this :

Code:
  @Override
  @OneToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "ID_BOX", nullable = false, insertable = false, updatable = false)
  @OnDelete(action = OnDeleteAction.CASCADE)
  public BoxWcsKlEntityBean getBox() {
    return super.getBox();
  }


But it fails with a duplicate column name ID_BOX.

Any idea of what happens ?

Thanks in advance for your answer.

Steve


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.