I have to do a project using JPA + Hibernate in which I'm using 3 dialects: MySQL5InnoDBDialect, MSSQL2012Dialect and Oracle12cDialect.
Right now I have a specification which is telling me that for some column from:
Oracle database, I have to use NVARCHAR2(LENGTH) data type
MySql database, I have to use VARCHAR(LENGTH) data type
MSSQL database, I have to use NVARCHAR(LENGTH) data type
... and here is my problem..
If I use:
@Column(name="columnName" length = 255) private String columnName; hibernate generates varchar(255) and this is good just for MySQL
If I use:
@Column(name="columnName", columnDefinition="nvarchar2(255)") private String columnName; it's not possible in MySQL, i get error because of columnDefinition, but in oracle is okay
I tried to customize MySQL dialect creating
public class CustomMySQL5InnoDBDialect extends MySQL5InnoDBDialect{
public CustomMySQL5InnoDBDialect() { super(); registerColumnType(Types.NVARCHAR, "nvarchar2($l)");//$l not $1 registerHibernateType(Types.NVARCHAR, StandardBasicTypes.STRING.getName()); }}
and giving this class in hibernate configuration for MySQL dialect. I have the same problem in MySQL if I'm using columnDefinition property.
Can you help with this problem please?