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.  [ 4 posts ] 
Author Message
 Post subject: Should I build referential integrity in MySQL?
PostPosted: Sat May 17, 2008 2:38 pm 
Newbie

Joined: Sat May 17, 2008 2:34 pm
Posts: 1
Should I build in referential integrity in my MySQL database (InnoDB) or let Hibernate handle it?

Some ORM solutions recommend letting the ORM handle it, not the db.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 17, 2008 4:39 pm 
Newbie

Joined: Fri May 16, 2008 3:40 pm
Posts: 13
If you ever plan to access your data by other means than your hibernate-using application (one of the great advantages of using a rdbms as persistance storage that you can), you should have all referential integrity in the db and not only rely on the ORM.

A simple example would be if you have to import data from a legacy application. Not having integrity constraints in the DB would allow import of data that could completely mess up your application - NullPointerExceptions guaranteed.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 17, 2008 6:36 pm 
Beginner
Beginner

Joined: Wed Dec 20, 2006 11:21 am
Posts: 20
And even if you only use Hibernate, I would recommend referential integrity.

For example let's suppose you have an object having a collection of other objects (in a Map for example). If you load one of the object in the collection via session.load() and then delete it, I am not sure Hibernate will automatically delete it from the collections as well (it is your responsability to do so, I think) and then later you will have exceptions because one of the items in the collection is no longer in the DB. With referential integrity you are protected from that.

PS: can someone confirm that indeed Hibernate won't delete it from any collection where the object may be in?


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 17, 2008 9:09 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Referential integrity at the database level should never be sidestepped. You simply can't trust your Hibernate developers to get it right, every time. The integrity check at the database level will help to keep everyone honest.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.