Tell Hibernate's hbm2ddl to add MySQL enum columns for @Enumerated annotated fields -


i'm creating db table using hbm2ddl java code similar following:

@entity public  class filter {     public enum type {         typea, typeb;     }     @enumerated(enumtype.string)     private type type; } 

it works fine, "type" varchar column created, i.e. ddl code looks this:

create table if not exists `filter` (`type` varchar(255) default null) 

but want have this:

create table if not exists `filter` (`type` enum('typea','typeb') not null) 

is possible declare in hibernate, preferred annotations?

or there way extend schemaupdate , overwrite method renders alter script part enumerated field way it?

background: same database used in php part of project , want prevent invalid values inserted.

i believe that's going complicated, since java.sql.types, define sql types treated java, not have enum type (since it's not standardized type according sql-92).

if was case create hibernate custom usertype extending enumtype , setting sqltype accordingly, since java.sql.types doesn't handle don't see how use native sql enum.

best regards!


Comments