13 Replies Latest reply on Dec 29, 2006 9:08 AM by gaboo

    geam-gen generate-entities error

    gaboo

      I'm trying to generate entities from an existing database.

      For this table :

      CREATE TABLE `abocc` (
       `ct` int(11) NOT NULL default '0',
       `dt_creat` datetime default NULL,
       `dt_modif` datetime default NULL,
       `dp_use` char(1) NOT NULL default 'O',
       `ct_pers` int(11) NOT NULL default '0',
       `ty` char(4) NOT NULL default '',
       `lb` char(39) default NULL,
       `ct_ref` int(11) default NULL,
       `dt_bgn` datetime default NULL,
       `dt_end` datetime default NULL,
       `dt_bgn_test` datetime default NULL,
       `dt_end_test` datetime default NULL,
       `nb_div` smallint(6) default '12',
       `nb_ren` smallint(6) default '12',
       `nb_ofs` smallint(6) default '0',
       `dp_rglt_post` char(1) default 'N',
       `mt_ht` float(7,2) default NULL,
       `tx_tva` float(6,1) default '19.6',
       PRIMARY KEY (`ct`),
       UNIQUE KEY `ct_pers` (`ct_pers`,`ty`,`ct`),
       UNIQUE KEY `ty` (`ty`,`ct_pers`,`ct`),
       UNIQUE KEY `dp_use` (`dp_use`,`ct`)
      ) ENGINE=MyISAM DEFAULT CHARSET=latin1 |


      I get an error when trying to compile generated java files :
      [javac] Compiling 69 source files to /home/gaboo/workspace/testSeamLrb/exploded-archives/testSeamLrb.jar
       [javac] /home/gaboo/workspace/testSeamLrb/src/com/lrb/testSeamLrb/Abocc.java:20: '}' expected
       [javac] , uniqueConstraints = { @UniqueConstraint(columnNames={"ct_pers", "ty", "ct"}) @UniqueConstraint(columnNames={"dp_use", "ct"}) }
       [javac] ^
      


      Here is the generated annotation :
      /**
       * Abocc generated by hbm2java
       */
      @Entity
      @Table(name="abocc"
       ,catalog="lrb"
       , uniqueConstraints = { @UniqueConstraint(columnNames={"ct_pers", "ty", "ct"}) @UniqueConstraint(columnNames={"dp_use", "ct"}) }
      )
      public class Abocc implements java.io.Serializable {
      
      


      There is indeed several unique keys constraints. Obviously, the annotation syntax is not correct. I've not found an example annotation with two unique constraints either on hibernate documentatin or searching on google.

      I though it is a hibernate problem but the hibernate site asks us to come here if it's seam related.

      Thanks for your help.

        • 1. Re: geam-gen generate-entities error
          gaboo

          There's an error in the topic title. Editing a post is disabled ?

          • 2. Re: geam-gen generate-entities error
            gaboo

            no ideas ?

            • 3. Re: geam-gen generate-entities error
              pmuir

              Put a comma between the two @UniqueConstraints. You should also report to the hibernate-tools guys I think as it is an error in the templates.

              • 4. Re: geam-gen generate-entities error
                maxandersen

                yes, this was a bug in the build of hibernatetools used in seamgen. i have fixed it in hibernatetools svn and is about to commit a fixed build to seamgen.

                • 5. Re: geam-gen generate-entities error
                  gaboo

                  I tried with latest CVS seam version and seam gen did not worked :

                  20:50:13 gaboo@muadib:~/workspace/jboss-seam$ ./seam setup
                  Buildfile: build.xml
                  
                  BUILD FAILED
                  /home/gaboo/workspace/jboss-seam/seam-gen/build.xml:15: taskdef class org.jboss.seam.tool.PathFilenameTask cannot be found
                  
                  Total time: 0 second


                  I also tried with seam 1.1GA and replace its hibernate-tools.jar with the one from my CVS checkout : same errors as before.

                  Any idea on how to get a working fixed version of seam ?
                  Thank you !

                  • 6. Re: geam-gen generate-entities error

                    Try building clean - it is there.

                    • 7. Re: geam-gen generate-entities error
                      gaboo

                      Indeed, it works :)

                      But, I found another problem, maybe it is configurable :

                      generate-entities works, but crashes once deployed if there is a column which type is char(X) with X > 1.

                      It works with X=1.

                      For example, it works with the above abocc table if I change ty and lb columns to be varchar instead of char.

                      • 8. Re: geam-gen generate-entities error

                        For database? I tried with mysql. A column of type char(255) mapped was reverse engineered to a String.

                        If it looks like a hibernate bug, please report it to the hibernate tools team. If it is a seam-gen issue, feel free to open up a JIRA case here. (or post more info so I can)

                        • 9. Re: geam-gen generate-entities error
                          gaboo

                          Dunno If it's related to hibernate ot not, maybe. Please tell me if so and I will report the problem to hibernate.

                          Here is more information : if I have a char(X) column in a mysql table which is reverse engineered using generate-entities (which runs successfully) I get these errors in my jboss as output :

                          11:25:23,740 INFO [SchemaValidator] Running schema validator
                          11:25:23,740 INFO [SchemaValidator] fetching database metadata
                          11:25:23,763 INFO [TableMetadata] table found: lrb.abocc
                          11:25:23,763 INFO [TableMetadata] columns: [dt_bgn_test, dp_rglt_post, dp_use, dt_end_test, nb_div, nb_ren, dt_end, dt_creat, dt_bgn, nb_ofs, tx_tva, mt_ht, dt_modif, ct_pers, ct_ref, ty, lb, ct]
                          11:25:23,765 WARN [ServiceController] Problem starting service persistence.units:ear=lrbseamtest.ear,unitName=lrbseamtest
                          javax.persistence.PersistenceException: org.hibernate.HibernateException: Wrong column type: ty, expected: varchar(4)
                           at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:698)
                           at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:127)
                           at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:264)
                           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                           at java.lang.reflect.Method.invoke(Method.java:585)
                           at org.jboss.ejb3.ServiceDelegateWrapper.startService(ServiceDelegateWrapper.java:102)
                           at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
                           at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
                           at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
                           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                           at java.lang.reflect.Method.invoke(Method.java:585)
                           at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                           at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                           at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                           at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                          


                          and then at the end :

                          11:25:26,212 INFO [StartupServletContextListener] Serialization provider : class org.apache.myfaces.shared_impl.util.serial.DefaultSerialFactory
                          11:25:26,250 INFO [EARDeployer] Started J2EE application: file:/home/gaboo/progs/jboss-4.0.5.GA/server/default/deploy/lrbseamtest.ear/
                          11:25:26,251 ERROR [URLDeploymentScanner] Incomplete Deployment listing:
                          
                          --- MBeans waiting for other MBeans ---
                          ObjectName: persistence.units:ear=lrbseamtest.ear,unitName=lrbseamtest
                           State: FAILED
                           Reason: javax.persistence.PersistenceException: org.hibernate.HibernateException: Wrong column type: ty, expected: varchar(4)
                           I Depend On:
                           jboss.jca:service=DataSourceBinding,name=lrbseamtestDatasource
                          
                          --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
                          ObjectName: persistence.units:ear=lrbseamtest.ear,unitName=lrbseamtest
                           State: FAILED
                           Reason: javax.persistence.PersistenceException: org.hibernate.HibernateException: Wrong column type: ty, expected: varchar(4)
                           I Depend On:
                           jboss.jca:service=DataSourceBinding,name=lrbseamtestDatasource


                          • 10. Re: geam-gen generate-entities error
                            gaboo

                            one more note : I tried with a char(255) and i get the same error.

                            • 11. Re: geam-gen generate-entities error
                              maxandersen

                              report to hibernate tools jira with the (minimal) schema that reproduces the error - thank you.

                              • 12. Re: geam-gen generate-entities error

                                In the meantime you can turn schema validation off in your persistence.xml.

                                • 13. Re: geam-gen generate-entities error
                                  gaboo

                                  It workd if I use

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

                                  Thanks!
                                  Anyway, I'll experiment a bit more and I will probably report this to hibernate.