2008年3月8日土曜日

[Groovy>Grails]Database Dialect

Description
Grails Framework uses the Hibernate object/relational persistence and query service Tools between Database and Application. We sometimes have to compatible with various kind of Database. For example, We need to add the "create table" statement with Engine Type Dialect in case of using MySQL DB. It can handle the different dialects by using "dialect" variable in the DataSource.groovy configuration file.

References
  • Grails Home
    http://grails.codehaus.org/
  • Hibernate
    http://www.hibernate.org/
  • http://hartsock.blogspot.com/2007/11/grails-datasource-legacy-database-and.html
Solution
We can specify the hibernate database dialect class into the "dialect" variable in the grails-app/conf/DataSource.groovy Configuration file to handle the Database dialects. In case of using MySQL, we can add
"dialect=org.hibernate.dialect.MySQLInnoDBDialect" or "dialect=org.hibernate.dialect.MySQLMyISAMDialect"
into this file to handle the storage engines of database tables.
Please check the Dialect classes if you need to handle other database dialects.
http://www.hibernate.org/hib_docs/v3/api/org/hibernate/dialect/Dialect.html

Example of DataSource.groovy file under the grails-app/conf directory
  dbCreate = "create-drop" // one of 'create', 'create-drop','update'
url = "jdbc:mysql://localhost:5000/test_database
driverClassName = "com.mysql.jdbc.Driver"
username = "epic_admin"
password = "tskr0511epic"
//dialect = org.hibernate.dialect.MySQLInnoDBDialect
dialect = org.hibernate.dialect.MySQLMyISAMDialect

0 件のコメント: