]
Diego Pires Plentz resolved HHH-2261.
-------------------------------------
Assignee: Diego Pires Plentz
Resolution: Fixed
Fix Version/s: 3.2.6
Setting hibernate.hbm2ddl.auto=validate causes problems on mySQL with
numeric fields
------------------------------------------------------------------------------------
Key: HHH-2261
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2261
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.1
Reporter: Christian Sprajc
Assignee: Diego Pires Plentz
Fix For: 3.2.6
Hello,
We got a Problem when using the following setup:
1) JBoss 4.0.4A with Hibernate 3.2.0 / mySQl 4.x AND 5.x
2) Set hibernate.hbm2ddl.auto=validate
3) Using a usertype which uses the SQL type: Types.NUMERIC
When deploying our application I got the following error:
12:43:21,985 INFO [TableMetadata] columns: [paymenttype, amount, oid, remarks, currency,
ae_date]
12:43:21,985 WARN [ServiceController] Problem starting service
persistence.units:jar=com.riege.pogo_0.1.4.jar,unitName=PogoEntityManager
org.hibernate.HibernateException: Wrong column type: amount, expected: numeric(19,2)
at org.hibernate.mapping.Table.validateColumns(Table.java:251)
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1002)
The Problem is:
1) When hibernate creates (e.g. hibernate.hbm2ddl.auto=update) through the columns in the
mySQL database it creates it as "numeric(x,y)" field.
2) mySQL always converts "numeric(x,y)" to "decimal(x,y)". The
metadata returns "decimal(x,y)"
3) When deploying with "hibernate.hbm2ddl.auto=validate" to error above is
thrown. The problem is that hibernate expects a "numeric(x,y)" type but mysql
returns a "decimal(x,y)"
A workaround I'm now using is a fixed mySQL dialect which correctly handles
Types.DECIMAL / "decimal(x,y)":
public class FixedMySQLDialect extends org.hibernate.dialect.MySQLDialect {
public FixedMySQLDialect() {
super();
registerColumnType(Types.NUMERIC, "decimal(19, $l)");
registerColumnType(Types.DECIMAL, "decimal(19, $l)");
}
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: