I had a little problem while working on a JBoss Seam project: I used the MySQL decimal(10,2) type for price value but, while running seam tests, the hbm2ddl schema validator gave me this error:

Caused by: org.hibernate.HibernateException: Wrong column type: shippingCost, expected: numeric(10,0)
[testng]     at org.hibernate.mapping.Table.validateColumns(Table.java:261)
[testng]     at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1083)
[testng]     at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:116)
[testng]     at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:317)
[testng]     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
[testng]     at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:918)
[testng]     at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:656)
[testng]     … 68 more

The problem is that hbm2java usa a wrong column definition for the entity property, in fact the @Column annotation on the property was:

@Column(name = “shippingCost”, nullable = false, precision = 10)

The solution is simple, just change it to:

@Column(name = “shippingCost”, nullable = false, precision = 10, scale=2, columnDefinition=”decimal(10,2)”)

Now the type is correctly defined and the schema validator doesn’t return any error.

Demetrio

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • Technorati
Trackback

no comment untill now

Add your comment now

Currently you have JavaScript disabled. In order to post comments, please make sure JavaScript and Cookies are enabled, and reload the page. Click here for instructions on how to enable JavaScript in your browser.