• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to set the charset of tables using hbm2ddl?

Steven Gollery
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using the ant hibernatetool and hbm2ddl tasks to generate the sql for creating tables from .hbm.xml files. I would like to set the charset of the generated tables to utf-8, so the last line of each create table command comes out something like:

} type=InnoDB default charset=utf8;

Currently, the hbm2ddl looks like this:

<hbm2ddl export="false" outputfilename="schema.sql" drop="true" format="true" />

In hibernate.cfg.xml, I have the dialect set to org.hibernate.dialect.MySQLInnoDBDialect, which gives me the 'type=InnoDB' part, but so far I haven't been able to find any help about setting the charset.

Is there an attribute I can add here, or a property I can set in the hibernate configuration file, that will cause hbm2ddl to output 'default charset=utf8" at the end of every 'create table' statement?

I'm using Hibernate 5.0.27 on Linux and 5.0.22-community on XP.

Thanks in advance,

Steve Gollery
Arun Kumarr
Ranch Hand
Posts: 662
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if you can do that in hibernate.
But I can suggest some alternatives:
1. Try if there are any settings in the tool you use to convert the <hbm2ddl>.
2. While creating the Database you can set the default values for char Set.

CREATE DATABASE your_db_name
[DEFAULT] COLLATE latin1_swedish_ci;
3. When you start the MySQL server try if you can start the server with default options for charset.

Ping back if none of this had worked.
I just had the craziest dream. This tiny ad was in it.
the new thread boost feature brings a LOT of attention to your favorite threads
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!