-->
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 for Secondary Table?
PostPosted: Thu Mar 27, 2008 7:21 am 
Newbie

Joined: Thu Mar 27, 2008 6:51 am
Posts: 2
Hi,

I'm using Hibernate 3.2.

I'm wondering how to set cascades for secondary tables. I have an object A and an object B, with A keeping a reference to B, and B being a serialisable, big object.

I want them to be put in two different tables, like that:

Code:
-----------      -----------------------
|A        |      | B                   |
-----------      -----------------------
|id     PK|      | A_id    PK, FK(A.id)|
-----------      | myB            BLOB |
                 -----------------------     


I can achive this by using the secondary table annotation:

Code:
@Entity
@SecondaryTables({
    @SecondaryTable(name = "B", pkJoinColumns = {
        @PrimaryKeyJoinColumn(name = "a_id", referencedColumnName = "id")}
    )}
)
@Table(appliesTo = "B", optional = true)
class A {
  long id;

  @Lob
  @Column(table = "iegm_objects", nullable = true)
  B myB;
}

class B implements Serialisable {
[...]
}


It works exactly how I expect it, but I would like to have some cascade options set in table B:

On update or on delete of the corresponding A instance, the B instance should be deleted as well. Hibernates currently only creates this code:

Code:
CREATE TABLE `B` (
  `myB` blob,
  `a_id` bigint(20) NOT NULL,
  PRIMARY KEY  (`a_id`),
  KEY `FK7A6A8CD763006FDE` (`a_id`),
  CONSTRAINT `FK7A6A8CD763006FDE` FOREIGN KEY (`a_id`) REFERENCES `A` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8


But I would like it to create that code instead:

Code:
CREATE TABLE `B` (
  `myB` blob,
  `a_id` bigint(20) NOT NULL,
  PRIMARY KEY  (`a_id`),
  KEY `FK7A6A8CD763006FDE` (`a_id`),
  CONSTRAINT `FK7A6A8CD763006FDE` FOREIGN KEY (`a_id`) REFERENCES `A` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8


How can I achive that ON DELETE CASCADE ON UPDATE CASCADE are added?

Bernhard


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.