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