-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate, database, foreign key, cascade question
PostPosted: Fri May 30, 2008 2:53 pm 
Newbie

Joined: Fri May 30, 2008 2:20 pm
Posts: 1
I have a general question that I can't seem to find a solid answer to so I will post it here:

Hibernate gives us the option to specify 1-1, 1-N, N-1, N-M relationships and also cascading options as well. What about the database level options for cascading after specifying foreign keys and such at the database level?

Example:

Code:
CREATE TABLE parent (
    id INT NOT NULL,
    PRIMARY KEY (id)
) ENGINE=INNODB;

CREATE TABLE child (
    id INT,
    parent_id INT,
    FOREIGN KEY (parent_id) REFERENCES parent(id)
        ON DELETE CASCADE
) ENGINE=INNODB;


How does the equivalent hbm.xml file look like for this requirement? Do I need to create these tables with the FOREIGN KEY? If not, does the application need to handle this relationship? Is there a way to keep the FOREIGN KEY option so that the database can handle this relationship instead of hibernate? What are my options?


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 31, 2008 8:00 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
at least with annotations this is possible see @OnDelete

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.