1 Reply Latest reply on Dec 14, 2008 1:42 PM by maxandersen

    Hibernate validation failure with Seamgen/MYSQL

    bdlink

      This is not new, and may belong with the hibernate people (just tell me).

      Using windows XP, latest daily build of JBT 3.

      Have a mysql database with a fixed width field STATE char(2) and some varchar fields. (mysql shows the column type for STATE as char(2))

      Seam gen entities generates (in the code)
      @Column(name = "STATE", length = 2)
      @Length(max = 2)
      (similarly for the varchar fields, no difference other than the 2 lengths)
      In the persistence.xml, seamgen generates

      Application fails to load with following traceback (partial):

      Caused by: org.hibernate.HibernateException: Wrong column type: STATE, expected: varchar(2)
       at org.hibernate.mapping.Table.validateColumns(Table.java:261)
       at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1083)
       at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:116)
       at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:317)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
       at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713)

      I note that in the JBDS 2 Beta 1, the persistence.xml is autogenerated with update, not validate. I can make the error go away by adding columnDefinition="char(2)" to the column attribute.

      I guess I feel generate entities should generate correct entities in the presence of fixed length character fields.


        • 1. Re: Hibernate validation failure with Seamgen/MYSQL
          maxandersen

          this is the validator being wrong; the colum type is perfectly ok for that type.

          Known issue in Hibernate jira.

          To make the validator (wrongly) happy we should generate char[2] fields in your java code which would be wrong too (or do you prefer to have to manipulate arrays instead of strings ? if yes, you can use a reveng.xml to set the type for sql type char with length 2 to the hibernate type character)