8 Replies Latest reply on Oct 26, 2007 6:01 AM by Pete Muir

    seam-gen generate entities errors

    Bruce Link Newbie

      Saw something similar in JIRA regarding Temporal fields, but that is not an issue here.

      Running Seam 2.0.0.CR2 with JDK 1.5.0_12 and JBoss4.2.1.GA and eclipse3.3.1 with JBoss Tools2.0.0.beta4 installed.

      Created a new project with seamgen new-project with the following properties:

      #Generated by seam setup
      #Sun Oct 21 13:21:48 PDT 2007
      hibernate.connection.password=changed
      workspace.home=C\:/Documents and Settings/blink/workspace33
      model.package=ca.bcit.infosys.entity
      hibernatetool.metadatadialect=org.hibernate.cfg.reveng.dialect.MySQLMetaDataDialect
      driver.jar=lib/mysql-connector-java-5.0.7-bin.jar
      action.package=ca.bcit.infosys.session
      test.package=ca.bcit.infosys.test
      database.type=mysql
      richfaces.skin=blueSky
      hibernate.default_catalog.null=
      hibernate.default_schema.null=
      database.drop=n
      project.name=infosys
      hibernate.connection.username=changed
      hibernate.connection.driver_class=com.mysql.jdbc.Driver
      hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider
      project.type=ear
      icefaces.home=
      database.exists=y
      jboss.home=C\:/apps/jboss-4.2.1.GA
      hibernate.dialect=org.hibernate.dialect.MySQLDialect
      hibernate.connection.url=jdbc\:mysql\://localhost\:3306/infosys
      


      then generated entities from the mysql database. No errors from seamgen script.

      Code generated did not compile due to duplicate names (the type was used instead of the column name for the variable name - column name would be better). After fixing this so it would compile, project would not deploy.

      Error:
      11:40:40,929 INFO [SchemaValidator] Running schema validator
      11:40:40,929 INFO [SchemaValidator] fetching database metadata
      11:40:40,999 INFO [TableMetadata] table found: infosys.review
      11:40:40,999 INFO [TableMetadata] columns: [comments, ratepersonal3, reviewer, rateleadership4, tech4, ratepersonal4, ratetask1, id, ratepersonal5, ratetech1, ratetask3, ratetask6, rateleadership2, ratepersonal2, tech3, summary, period, received, ratetask8, ratepersonal7, reviewtype, ratetech2, rateleadership1, ratetask5, ratepersonal8, ratetask7, ratetask2, rateleadership3, tech1, ratetech4, year, pos, ratepersonal1, employee, ratepersonal6, ratetech3, tech2, ratetask4]
      11:40:41,009 WARN [ServiceController] Problem starting service persistence.units:ear=infosys.ear,unitName=infosys
      javax.persistence.PersistenceException: org.hibernate.HibernateException: Wrong column type: id, expected: varchar(32)
       at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:720)
       at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:127)
       at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:246)
      

      The generated annotation for the Review class is as follows:
      @Entity
      @Table(name = "review", catalog = "infosys")
      public class Review implements java.io.Serializable {
      
       private String id;
      ...
       @Id
       @Column(name = "id", unique = true, nullable = false, length = 32)
       @NotNull
       @Length(max = 32)
       public String getId() {
       return this.id;
       }
      ...
      


      Following is the schema of the review table:
      CREATE TABLE `review` (
       `id` char(32) NOT NULL,
       `employee` varchar(32) default NULL,
       `pos` varchar(20) default NULL,
       `reviewer` varchar(32) default NULL,
       `received` datetime default NULL,
       `period` tinyint(4) default NULL,
       `year` smallint(4) unsigned default NULL,
       `reviewType` varchar(20) default NULL,
       `tech1` varchar(35) default NULL,
       `rateTech1` tinyint(3) unsigned default NULL,
       `tech2` varchar(35) default NULL,
       `rateTech2` tinyint(3) unsigned default NULL,
       `tech3` varchar(35) default NULL,
       `rateTech3` tinyint(3) unsigned default NULL,
       `tech4` varchar(35) default NULL,
       `rateTech4` tinyint(3) unsigned default NULL,
       `rateTask1` tinyint(3) unsigned default NULL,
       `rateTask2` tinyint(3) unsigned default NULL,
       `rateTask3` tinyint(3) unsigned default NULL,
       `rateTask4` tinyint(3) unsigned default NULL,
       `rateTask5` tinyint(3) unsigned default NULL,
       `rateTask6` tinyint(3) unsigned default NULL,
       `rateTask7` tinyint(3) unsigned default NULL,
       `rateTask8` tinyint(3) unsigned default NULL,
       `ratePersonal1` tinyint(3) unsigned default NULL,
       `ratePersonal2` tinyint(3) unsigned default NULL,
       `ratePersonal3` tinyint(3) unsigned default NULL,
       `ratePersonal4` tinyint(3) unsigned default NULL,
       `ratePersonal5` tinyint(3) unsigned default NULL,
       `ratePersonal6` tinyint(3) unsigned default NULL,
       `ratePersonal7` tinyint(3) unsigned default NULL,
       `ratePersonal8` tinyint(3) unsigned default NULL,
       `rateLeadership1` tinyint(3) unsigned default NULL,
       `rateLeadership2` tinyint(3) unsigned default NULL,
       `rateLeadership3` tinyint(3) unsigned default NULL,
       `rateLeadership4` tinyint(3) unsigned default NULL,
       `summary` tinyint(3) unsigned default NULL,
       `comments` text,
       PRIMARY KEY (`id`),
       KEY `employee` (`employee`),
       KEY `reviewer` (`reviewer`),
       CONSTRAINT `review_ibfk_1` FOREIGN KEY (`employee`) REFERENCES `student` (`id`),
       CONSTRAINT `review_ibfk_2` FOREIGN KEY (`reviewer`) REFERENCES `student` (`id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
      


      The names chosen for the foreign keys are studentForEmployee and studentForReviewer. Although these work, just using the column names of employee and reviewer would be preferable.

      The code create in ReviewHome is also in error (as mentioned above):
      @Name("reviewHome")
      public class ReviewHome extends EntityHome<Review> {
      
       @In(create = true)
       StudentHome studentHome;
       @In(create = true)
       StudentHome studentHome;
      ...
       public void wire() {
       Student studentByEmployee = studentHome.getDefinedInstance();
       if (studentByEmployee != null) {
       getInstance().setStudentByEmployee(studentByEmployee);
       }
       Student studentByReviewer = studentHome.getDefinedInstance();
       if (studentByReviewer != null) {
       getInstance().setStudentByReviewer(studentByReviewer);
       }
       }
      
      

      Here there is no mention (in the instance variables) that one of these is to correspond to the employee column, the other to the review column. What would be reasonable to do here is a good question.


      Any suggestions on how to get the project to deploy? My next step is to dig into hibernate and jboss docs to turn on more logging to see what specifically it is complaining about.

        • 1. Re: seam-gen generate entities errors
          Bruce Link Newbie

          Sorry, forgot to post persistence.xml file seamgen produced, related to above issues:

          <!-- Persistence deployment descriptor for dev profile -->
          <persistence xmlns="http://java.sun.com/xml/ns/persistence"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
           version="1.0">
          
           <persistence-unit name="infosys">
           <provider>org.hibernate.ejb.HibernatePersistence</provider>
           <jta-data-source>java:/infosysDatasource</jta-data-source>
           <properties>
           <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
           <property name="hibernate.hbm2ddl.auto" value="validate"/>
           <property name="hibernate.cache.use_query_cache" value="true"/>
           <property name="hibernate.show_sql" value="true"/>
           <property name="jboss.entity.manager.factory.jndi.name" value="java:/infosysEntityManagerFactory"/>
           </properties>
           </persistence-unit>
          
          </persistence>


          • 2. Re: seam-gen generate entities errors
            Bruce Link Newbie

            Commenting out the line in the persistence-dev.xml file removes the error and allows the generated project to work.

            • 3. Re: seam-gen generate entities errors
              Bruce Link Newbie

              Problem line:

              <property name="hibernate.hbm2ddl.auto" value="validate"/>


              • 4. Re: seam-gen generate entities errors
                Pierre Raoul Novice

                The line

                <property name="hibernate.hbm2ddl.auto" value="validate"/>
                


                is not the problem. It's just the tool which tells you that you have a problem with the column type of column id:

                Wrong column type: id, expected: varchar(32)
                


                Here the issue may be with the MySql dialect. I had the same type of error with bit type and Hsqldb dialect.

                Check hibernate forum.

                • 5. Re: seam-gen generate entities errors
                  Bruce Link Newbie

                  Perhaps it is related to the fact(according to mysql documentation) that mysql will silently change the char(32) field (which shows as char(32) in the schema) to a varchar(32) that is actually stored.

                  If you describe the table from mysql, it shows char(32), perhaps this was read to generate the entities, and somehow the validation is finding about the silent change in column type.

                  According to mysql documentation (13.1.5.1. Silent Column Specification Changes), "this does not affect how you use the columns in any way".

                  Since hibernate is generating the java, and doing the validation, it may be a hibernate bug, nothing to do with seamgen?

                  • 6. Re: seam-gen generate entities errors
                    Pierre Raoul Novice

                     

                    nothing to do with seamgen


                    I think so.

                    You can try:
                    - to add
                    sql-type="char(32)"

                    in

                    @Column(name = "id", unique = true, nullable = false, length = 32)



                    - or to extend MySQLDialect class.

                    • 7. Re: seam-gen generate entities errors
                      Bruce Link Newbie

                      Tried with seam2.0.0.CR3, same errors.

                      As suggested, adding columnDefinition="char(32)" to the id key fixes the problem with hibernate validation.

                      • 8. Re: seam-gen generate entities errors
                        Pete Muir Master

                        Make sure you bring this to hibernate tools team's attention at http://tools.hibernate.org