-->
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 tools (hbm2ddl) performance problem with mysql
PostPosted: Thu Sep 11, 2008 3:38 am 
Beginner
Beginner

Joined: Fri Aug 22, 2008 5:49 am
Posts: 22
Hibernate Core version: 3.3.0.SP1
Hibernate annotations version: 3.4.0.GA
Hibernate Tool version: 3.2.2
Name and version of the database you are using: MySQL 5.1.26-rc

I use hibernate tool (hbm2ddl) with Ant to export the schema into DB, in the DDL-file, i got code like this:

Code:
...
...
create table ColumnLayout (_id varchar(36) not null unique, _version integer, _active bit not null, _enabled bit not null, _identifier varchar(255), _name varchar(255), _order integer not null, _visible bit not null, _width integer not null, tablelayout_id varchar(36), sort_idx integer, primary key (_id)) ENGINE=InnoDB;
...
...
alter table ColumnLayout add index fk_tblLayout2colLayout (tablelayout_id), add constraint fk_tblLayout2colLayout foreign key (tablelayout_id) references TableLayout (_id);


and this code is slowly as the code, what mysqldump exported like this:

Code:
CREATE TABLE `columnlayout` (
  `_id` varchar(36) COLLATE utf8_bin NOT NULL,
  `_version` int(11) DEFAULT NULL,
  `_active` bit(1) NOT NULL,
  `_enabled` bit(1) NOT NULL,
  `_identifier` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  `_name` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  `_order` int(11) NOT NULL,
  `_visible` bit(1) NOT NULL,
  `_width` int(11) NOT NULL,
  `tablelayout_id` varchar(36) COLLATE utf8_bin DEFAULT NULL,
  `sort_idx` int(11) DEFAULT NULL,
  PRIMARY KEY (`_id`),
  UNIQUE KEY `_id` (`_id`),
  KEY `fk_tblLayout2colLayout` (`tablelayout_id`),
  CONSTRAINT `fk_tblLayout2colLayout` FOREIGN KEY (`tablelayout_id`) REFERENCES `tablelayout` (`_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;



Through test i am sure, that "alter table" is to slowly. And i have 300 tables, but i don't have this Problem with PostgreSQL.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2008 3:56 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
This is as expected and the problem with the SQL generated by MYSQL is that is almost impossible to use it for creating the database. The reason is that the table has to be created in the correct order so that tables references in foreign keys are created first. Eg. this will fail unless the table 'tablelayout' has already been created.
Code:
CONSTRAINT `fk_tblLayout2colLayout` FOREIGN KEY (`tablelayout_id`) REFERENCES `tablelayout` (`_id`)


The simpler approach taken by Hibernate is to create all tables first, and then do a second step that creates all foreign keys.


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.