5 Replies Latest reply on Nov 15, 2007 1:44 PM by Max Rydahl Andersen

    seam-gen 'generate-entities' generates invalid code for tabl

    Volker Reichel Newbie

      Using seam-gen 'generate-entities' to generate a CRUD application from an existing PostgreSQL database does not generate working code.

      I have the follwing two tables in my database:
      Table t_user

      CREATE TABLE t_user
      (
       email character varying(255) NOT NULL,
       firstname character varying(255),
       lastname character varying(255),
       loginname character varying(255),
       "password" character varying(255),
       joined timestamp without time zone,
       CONSTRAINT t_user_pkey PRIMARY KEY (email)
      )
      

      and a second table t_user_roles
      CREATE TABLE t_user_roles
      (
       t_user_email character varying(255) NOT NULL,
       element integer,
       CONSTRAINT fk8fc22a14c7001400 FOREIGN KEY (t_user_email)
       REFERENCES t_user (email) MATCH SIMPLE
       ON UPDATE NO ACTION ON DELETE NO ACTION
      )
      


      element encodes which role a user is in.

      When I run seam generate-entities I get no errors or warnings
      C:\seam-buch\seam\jboss-seam-2.0.0.GA>seam generate-entities
      C:\seam-buch\jdk\jdk_1_5_0_12
      Buildfile: C:\seam-buch\seam\jboss-seam-2.0.0.GA\seam-gen\build.xml
      
      init:
      
      init-properties:
       [echo] c:/seam-buch/appserv/jboss-4.2.1.GA
      
      validate-workspace:
      
      validate-project:
      
      generate-entities:
       [echo] Reverse engineering database using JDBC driver C:/seam-buch/appserv/jboss-4.2.1.GA/server\default/lib/postgresql-8.2-506.jdbc2ee.jar
       [echo] project=c:/seam-buch/workspaceJBossTools/seamquizadmin
       [echo] model=com.seamguru.seamquizadmin
      [hibernate] Executing Hibernate Tool with a JDBC Configuration (for reverse engineering)
      [hibernate] 1. task: hbm2java (Generates a set of .java files)
      [hibernate] 14.11.2007 17:53:12 org.hibernate.cfg.Environment <clinit>
      [hibernate] INFO: Hibernate 3.2.5
      [hibernate] 14.11.2007 17:53:12 org.hibernate.cfg.Environment <clinit>
      [hibernate] INFO: hibernate.properties not found
      [hibernate] 14.11.2007 17:53:12 org.hibernate.cfg.Environment buildBytecodeProvider
      [hibernate] INFO: Bytecode provider name : cglib
      [hibernate] 14.11.2007 17:53:12 org.hibernate.cfg.Environment <clinit>
      [hibernate] INFO: using JDK 1.4 java.sql.Timestamp handling
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.reveng.OverrideRepository addFile
      [hibernate] INFO: Override file: c:\seam-buch\workspaceJBossTools\seamquizadmin\resources\seam-gen.reveng.xml
      [hibernate] 14.11.2007 17:53:13 org.hibernate.connection.DriverManagerConnectionProvider configure
      [hibernate] INFO: Using Hibernate built-in connection pool (not for production use!)
      [hibernate] 14.11.2007 17:53:13 org.hibernate.connection.DriverManagerConnectionProvider configure
      [hibernate] INFO: Hibernate connection pool size: 20
      [hibernate] 14.11.2007 17:53:13 org.hibernate.connection.DriverManagerConnectionProvider configure
      [hibernate] INFO: autocommit mode: false
      [hibernate] 14.11.2007 17:53:13 org.hibernate.connection.DriverManagerConnectionProvider configure
      [hibernate] INFO: using driver: org.postgresql.Driver at URL: jdbc:postgresql:seamDB
      [hibernate] 14.11.2007 17:53:13 org.hibernate.connection.DriverManagerConnectionProvider configure
      [hibernate] INFO: connection properties: {user=postgres, password=****}
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: RDBMS: PostgreSQL, version: 8.2.5
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.2 JDBC2 with NO SSL (build 506)
      [hibernate] 14.11.2007 17:53:13 org.hibernate.dialect.Dialect <init>
      [hibernate] INFO: Using dialect: org.hibernate.dialect.PostgreSQLDialect
      [hibernate] 14.11.2007 17:53:13 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
      [hibernate] INFO: Using default transaction strategy (direct JDBC transactions)
      [hibernate] 14.11.2007 17:53:13 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
      [hibernate] INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: Automatic flush during beforeCompletion(): disabled
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: Automatic session close at end of transaction: disabled
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: JDBC batch size: 15
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: JDBC batch updates for versioned data: disabled
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: Scrollable result sets: enabled
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: JDBC3 getGeneratedKeys(): disabled
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: Connection release mode: auto
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: Default batch fetch size: 1
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: Generate SQL with comments: disabled
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: Order SQL updates by primary key: disabled
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: Order SQL inserts for batching: disabled
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
      [hibernate] INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
      [hibernate] 14.11.2007 17:53:13 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
      [hibernate] INFO: Using ASTQueryTranslatorFactory
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: Query language substitutions: {}
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: JPA-QL strict compliance: disabled
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: Second-level cache: enabled
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: Query cache: disabled
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory createCacheProvider
      [hibernate] INFO: Cache provider: org.hibernate.cache.HashtableCacheProvider
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: Optimize cache for minimal puts: disabled
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: Structured second-level cache entries: disabled
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: Statistics: disabled
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: Deleted entity synthetic identifier rollback: disabled
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: Default entity-mode: pojo
      [hibernate] 14.11.2007 17:53:13 org.hibernate.cfg.SettingsFactory buildSettings
      [hibernate] INFO: Named query checking : enabled
      [hibernate] 14.11.2007 17:53:13 org.hibernate.connection.DriverManagerConnectionProvider close
      [hibernate] INFO: cleaning up connection pool: jdbc:postgresql:seamDB
      [hibernate] 14.11.2007 17:53:13 org.hibernate.tool.Version <clinit>
      [hibernate] INFO: Hibernate Tools 3.2.0.b10
      14.11.2007 17:53:13 org.hibernate.connection.DriverManagerConnectionProvider close
      INFO: cleaning up connection pool: jdbc:postgresql:seamDB
      [hibernate] 2. task: generic exportertemplate: view/list.xhtml.ftl
      [hibernate] 3. task: generic exportertemplate: view/view.xhtml.ftl
      [hibernate] 4. task: generic exportertemplate: view/view.page.xml.ftl
      [hibernate] 5. task: generic exportertemplate: view/edit.xhtml.ftl
      [hibernate] 6. task: generic exportertemplate: view/edit.page.xml.ftl
      [hibernate] 7. task: generic exportertemplate: src/EntityList.java.ftl
      [hibernate] 8. task: generic exportertemplate: view/list.page.xml.ftl
      [hibernate] 9. task: generic exportertemplate: src/EntityHome.java.ftl
      [hibernate] 10. task: generic exportertemplate: view/layout/menu.xhtml.ftl
      [javaformatter] Java formatting of 14 files completed. Skipped 0 file(s).
       [echo] Type 'seam restart' and go to http://localhost:8080/seamquizadmin
      
      BUILD SUCCESSFUL
      Total time: 3 seconds
      
      C:\seam-buch\seam\jboss-seam-2.0.0.GA>
      


      Running seam restart terminates without warning or error:

      C:\seam-buch\seam\jboss-seam-2.0.0.GA>seam restart
      C:\seam-buch\jdk\jdk_1_5_0_12
      Buildfile: C:\seam-buch\seam\jboss-seam-2.0.0.GA\seam-gen\build.xml
      
      init:
      
      init-properties:
       [echo] c:/seam-buch/appserv/jboss-4.2.1.GA
      
      validate-workspace:
      
      validate-project:
      
      restart:
       [echo] Restarting project 'seamquizadmin'
      
      init:
      
      compile:
       [javac] Compiling 14 source files to c:\seam-buch\workspaceJBossTools\seamquizadmin\exploded-archives\seamquizadmin.jar
      
      copyclasses:
      
      jar:
       [copy] Copying 1 file to c:\seam-buch\workspaceJBossTools\seamquizadmin\exploded-archives\seamquizadmin.jar\META-INF
       [copy] Copying 1 file to c:\seam-buch\workspaceJBossTools\seamquizadmin\exploded-archives\seamquizadmin.jar
      
      war:
       [copy] Copying 25 files to c:\seam-buch\workspaceJBossTools\seamquizadmin\exploded-archives\seamquizadmin.war
      
      ear:
      
      datasource:
      
      explode:
       [copy] Copying 16 files to c:\seam-buch\appserv\jboss-4.2.1.GA\server\default\deploy\seamquizadmin.ear\seamquizadmin.jar
       [copy] Copying 25 files to c:\seam-buch\appserv\jboss-4.2.1.GA\server\default\deploy\seamquizadmin.ear\seamquizadmin.war
      
      restart:
      
      BUILD SUCCESSFUL
      Total time: 2 seconds
      
      C:\seam-buch\seam\jboss-seam-2.0.0.GA>
      


      Then I tried to open the generated webapp in a browser:
      [img]http://www.seamguru.com/jbossforum/img/seamgenDBbug.jpg[/img]
      [urlhttp://www.seamguru.com/jbossforum/img/seamgenDBbug.jpg[/url]

      The error message tells me that class 'com.seamguru.seamquizadmin.TUserList' does not have a property 'tUser'.

      The generated class TUserList defines a member tUser and a getter (getTUser). When I change the getter to gettUser. Please note the lowercase 't' in TUser. I get one step further.
      Now I get a similar error for class TUserRoleList. Making similar change fixes this problem too.

      Now the home screen of the application is rendered correctly. But selecting 'TUserRolesList' from the menu on the top of the page gives a similar error message as the the two before. Now property 'tUserEmail' cannot be found.

      See [img]http://www.seamguru.com/jbossforum/img/seamDBBug2.png[/img]

      See http://www.seamguru.com/jbossforum/img/seamDBBug2.png

      My questions are:

      Has anyone else seen this error?

      Why does the error message complain about 'tUserEmail' / 'tUser' as far as I can see 'tUser' / 'tUserEmail' is not used in the XHTML pages?

      Any response welcome!

      Volker




      Environment Information:

      Seam 2.0.0.GA
      PostgreSQL 8.2
      JBoss 4.2.1.GA
      Windows XP
      Java 1.5


        • 2. Re: seam-gen 'generate-entities' generates invalid code for
          Volker Reichel Newbie

          I did some more research and have a theory what is happening:
          The error message tell us that 'tUser' is not a property of TUserList.
          When I change the getter to gettUser it is working.
          So I conclude BeanELResolver just concats 'get' + 'tUser' and does not obey the rules how to map property names to getter/setter methods.
          The code should uppercase the first letter of the property and then do the concatenation.

          Does someone know which class is responsible for scanning classes for properties?

          See the stacktrace for details:

          SCHWERWIEGEND: Error Rendering View[/home.xhtml]
          javax.el.PropertyNotFoundException: The class 'com.seamguru.seamquizadmin.TUserList_$$_javassist_0' does not have the property 'tUser'.
           at javax.el.BeanELResolver.getBeanProperty(BeanELResolver.java:574)
           at javax.el.BeanELResolver.getValue(BeanELResolver.java:280)
           at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)
           at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
           at org.jboss.el.parser.AstPropertySuffix.getValue(AstPropertySuffix.java:53)
           at org.jboss.el.parser.AstValue.getValue(AstValue.java:67)
           at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
           at org.jboss.seam.core.Expressions$1.getValue(Expressions.java:112)
           at org.jboss.seam.navigation.Param.getStringValueFromModel(Param.java:132)
           at org.jboss.seam.navigation.Pages.getStringValuesFromModel(Pages.java:688)
           at org.jboss.seam.ui.component.UISeamCommandBase.getUrl(UISeamCommandBase.java:51)
           at org.jboss.seam.ui.renderkit.LinkRendererBase.doEncodeBegin(LinkRendererBase.java:26)
           at org.jboss.seam.ui.util.cdk.RendererBase.encodeBegin(RendererBase.java:79)
           at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:788)
           at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:280)
           at org.richfaces.renderkit.html.ToolBarRendererBase.encodeChildren(ToolBarRendererBase.java:81)
           at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
           at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
           at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
           at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:216)
           at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
           at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
           at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
           at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
           at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
           at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
           at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
           at java.lang.Thread.run(Unknown Source)
          


          • 3. Re: seam-gen 'generate-entities' generates invalid code for
            Max Rydahl Andersen Master

            could also be the seam-gen code generation templates that are not doing the Right Thing.

            • 4. Re: seam-gen 'generate-entities' generates invalid code for
              Volker Reichel Newbie

              Max

              you pointed me into another direction which helped me to find the reason for this unexpected behavior.

              It seams as if seam-gen / hibernatetools cannot handle table names having the following format:

              a single character followed by underscore '_' followed by any other character sequence.

              The behavior only shows up with a single character before the underscore. Weired.

              • 5. Re: seam-gen 'generate-entities' generates invalid code for
                Max Rydahl Andersen Master

                can you give me an example of such table ?

                hibernate tools should handle that fine; e.g. x_customer should become XCustomer

                i still think it is in seam-gen templates about how it assumes casing of names...I don't think it using the methods we have in hibernate tools to figure that out (and if they are not easily available we just need to make them available)