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: How to take into account primary keys and foreign keys
PostPosted: Wed Feb 04, 2009 6:53 pm 
Newbie

Joined: Thu Dec 11, 2008 8:25 am
Posts: 1
Hi all,

I am using Hibernate Tools 3.2.4CR, Hibernate 3.2.5. GA and MySQL 5.1.
I succeeded to generate my *.hbm.xml, *.cfg.xml files, DB java classes for a MyISAM database.

Now that I am moving to InnoDB engine, I would like to have foreign keys be handled by Hibernate Tools.

I succeeded to generate the hibernate.cfg.xml by changing the database dialect to 'MySQL 5 (innodb)'.

Could someone tell me what is the right process to follow so that Hibernate Tools generate the proper Java classes for my InnoDB database?
(including proper handling of primary keys and foreign keys without having to edit manually the 'hibernate.reveng.xml')


Just for info, here is my SQL script:

-------------------- Begin MyDB.sql -------------------->

DROP TABLE IF EXISTS `Service`;
CREATE TABLE IF NOT EXISTS `Service` (
`serviceId` int(10) unsigned NOT NULL auto_increment,
`serviceName` enum('sms','alert','web','object','codelet','queue','vocal','barcode','videosecurity') NOT NULL,
`operatorId` int(11) unsigned NOT NULL,
PRIMARY KEY (`serviceId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=11;


DROP TABLE IF EXISTS `Ip`;
CREATE TABLE IF NOT EXISTS `Ip` (
`ipId` int(10) unsigned NOT NULL auto_increment,
`ipv4` char(15) NOT NULL,
`companyId` int(10) unsigned NOT NULL,
`serviceId` int(10) unsigned NOT NULL,
PRIMARY KEY (`ipId`),
KEY `Index_CompanyId_ServiceId` (`companyId`,`serviceId`),
KEY `Index_ServiceId` (`serviceId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=11;

ALTER TABLE `Ip`
ADD CONSTRAINT `ip_ibfk_2` FOREIGN KEY (`serviceId`) REFERENCES `service` (`serviceId`) ON DELETE CASCADE ON UPDATE CASCADE;


-------------------- End MyDB.sql -------------------->


Thank you for your help


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.