Uploaded image for project: 'Seam 2'
  1. Seam 2
  2. JBSEAM-2179

Seam-gen created pages show non-assigned ids

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Tools
    • Labels:
      None

      Description

      seam-gen intends to exclude non-assigned id's from the property edit and view pages - seam-gen\view\editproperty.xhtml.ftl, seam-gen\view\viewproperty.xhtml.ftl etc. They are being shown.

        Gliffy Diagrams

          Activity

          klawandronic Viorel Andronic created issue -
          Hide
          pmuir Pete Muir added a comment -

          What are you talking about?

          Show
          pmuir Pete Muir added a comment - What are you talking about?
          Hide
          klawandronic Viorel Andronic added a comment -

          Well, I believe that, with this condition: property.value.identifierGeneratorStrategy != "assigned" you want to eliminate autogenerated(AUTO, SEQUENCE, etc.) identifiers from the xhtml pages ... if this is the case, then, the desired behavior isn't happening.

          Show
          klawandronic Viorel Andronic added a comment - Well, I believe that, with this condition: property.value.identifierGeneratorStrategy != "assigned" you want to eliminate autogenerated(AUTO, SEQUENCE, etc.) identifiers from the xhtml pages ... if this is the case, then, the desired behavior isn't happening.
          pmuir Pete Muir made changes -
          Field Original Value New Value
          Description Change line 3 condition to property.value.identifierGeneratorStrategy != "assigned" in C:\rhdevstudio\jboss-eap\seam\seam-gen\view\editproperty.xhtml.ftl and in C:\rhdevstudio\jboss-eap\seam\seam-gen\view\viewproperty.xhtml.ftl to obtain the desired functionality: not showing auto-generated ids ... there are also other files where this change needs to be done, like list.xhtml.ftl and so on. seam-gen intends to exclude non-assigned id's from the property edit and view pages - seam-gen\view\editproperty.xhtml.ftl, seam-gen\view\viewproperty.xhtml.ftl etc. They are being shown.
          pmuir Pete Muir made changes -
          Summary Seam-gen doesn't recognize identifier properties properly Seam-gen
          pmuir Pete Muir made changes -
          Summary Seam-gen Seam-gen created pages show non-assigned ids
          Hide
          pmuir Pete Muir added a comment -

          I replicated this using a mysql ddl which generated (trimmed for readability):

          @Entity
          @Table(name = "Foo", catalog = "release")
          public class Foo implements java.io.Serializable {

          private Integer id;
          private String name;

          @Id
          @GeneratedValue(strategy = IDENTITY)
          @Column(name = "id", unique = true, nullable = false)
          public Integer getId()

          { return this.id; }

          @Column(name = "name")
          public String getName()

          { return this.name; }

          }

          seam-gen didn't generated view/edit section's for id, just for name.

          If you can attach a reproducible test case (I only have hsql or mysql) then please reopen.

          Show
          pmuir Pete Muir added a comment - I replicated this using a mysql ddl which generated (trimmed for readability): @Entity @Table(name = "Foo", catalog = "release") public class Foo implements java.io.Serializable { private Integer id; private String name; @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "id", unique = true, nullable = false) public Integer getId() { return this.id; } @Column(name = "name") public String getName() { return this.name; } } seam-gen didn't generated view/edit section's for id, just for name. If you can attach a reproducible test case (I only have hsql or mysql) then please reopen.
          pmuir Pete Muir made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Fix Version/s 2.0.0.GA [ 12311781 ]
          Resolution Cannot Reproduce Bug [ 5 ]
          Assignee Pete Muir [ pmuir ]
          Hide
          klawandronic Viorel Andronic added a comment -

          All code trimmed for readability.

          @Entity
          @Table(name = "group", schema = "security")
          public class Group implements java.io.Serializable {

          @Id
          @Column(name = "id", unique = true, nullable = false)
          @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "gen_group")
          @SequenceGenerator(name = "gen_group", sequenceName = "security.group_id_seq", allocationSize = 1)
          public int getId()

          { return this.id; }

          }

          I have a PostgreSQL database. I don't know if the DDL is usefull because you cannot replicate this on MySQL and this is the only way you can autoincrement an identifier when using PostgreSQL(this is actualy generated by PostgreSQL when declaring id as serial):

          CREATE TABLE "security"."group"
          (
          id integer NOT NULL DEFAULT nextval('"security".group_id_seq'::regclass),
          CONSTRAINT group_pkey PRIMARY KEY (id)
          )

          As seam-gen, or hibernate-tools doesn't know how to recognize(at least from what I know of) the DDL above and because I didn't manage to dig deep enough into hibernate-tools ftls, I added to seam-gen/pojo/GetPropertyAnnotation.ftl the following lines:

          <#-- To be used for "id" named columns defined as serial in PostgreSQL -->
          <#if property.equals(pojo.identifierProperty) && property.name.equals("id")>
          @$

          {pojo.importType("javax.persistence.GeneratedValue")}

          (strategy=$

          {pojo.importType("javax.persistence.GenerationType")}

          .SEQUENCE, generator="gen_$

          {clazz.table.name}")
          @${pojo.importType("javax.persistence.SequenceGenerator")}(name="gen_${clazz.table.name}

          ", sequenceName="$

          {clazz.table.schema}

          .$

          {clazz.table.name}

          _id_seq", allocationSize=1)
          </#if>

          and now my entities know how to map correctly these types of DDLs(but only if the identifier column is named id). So the generation of the entity above is done somehow artificially.

          What I believe now is the following: seam-gen uses the same information when building xhtml pages as when building entities and isn't aware of the two lines:

          @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "gen_group")
          @SequenceGenerator(name = "gen_group", sequenceName = "security.group_id_seq", allocationSize = 1)

          that specify that id is assigned.

          I don't know if this makes any sense ... but what i'm trying to say is that:

          ! Seam-gen should now how to recognize " id integer NOT NULL DEFAULT nextval('"security".group_id_seq'::regclass) " as an autoincrement column in PostgreSQL, or the generation of vieproperty, ediproperty or list should be done according to entities not table information !

          This is a major drawback in PostgreSQL because identifiers are not recognized properly.

          Show
          klawandronic Viorel Andronic added a comment - All code trimmed for readability. @Entity @Table(name = "group", schema = "security") public class Group implements java.io.Serializable { @Id @Column(name = "id", unique = true, nullable = false) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "gen_group") @SequenceGenerator(name = "gen_group", sequenceName = "security.group_id_seq", allocationSize = 1) public int getId() { return this.id; } } I have a PostgreSQL database. I don't know if the DDL is usefull because you cannot replicate this on MySQL and this is the only way you can autoincrement an identifier when using PostgreSQL(this is actualy generated by PostgreSQL when declaring id as serial): CREATE TABLE "security"."group" ( id integer NOT NULL DEFAULT nextval('"security".group_id_seq'::regclass), CONSTRAINT group_pkey PRIMARY KEY (id) ) As seam-gen, or hibernate-tools doesn't know how to recognize(at least from what I know of) the DDL above and because I didn't manage to dig deep enough into hibernate-tools ftls, I added to seam-gen/pojo/GetPropertyAnnotation.ftl the following lines: <#-- To be used for "id" named columns defined as serial in PostgreSQL --> <#if property.equals(pojo.identifierProperty) && property.name.equals("id")> @$ {pojo.importType("javax.persistence.GeneratedValue")} (strategy=$ {pojo.importType("javax.persistence.GenerationType")} .SEQUENCE, generator="gen_$ {clazz.table.name}") @${pojo.importType("javax.persistence.SequenceGenerator")}(name="gen_${clazz.table.name} ", sequenceName="$ {clazz.table.schema} .$ {clazz.table.name} _id_seq", allocationSize=1) </#if> and now my entities know how to map correctly these types of DDLs(but only if the identifier column is named id). So the generation of the entity above is done somehow artificially. What I believe now is the following: seam-gen uses the same information when building xhtml pages as when building entities and isn't aware of the two lines: @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "gen_group") @SequenceGenerator(name = "gen_group", sequenceName = "security.group_id_seq", allocationSize = 1) that specify that id is assigned. I don't know if this makes any sense ... but what i'm trying to say is that: ! Seam-gen should now how to recognize " id integer NOT NULL DEFAULT nextval('"security".group_id_seq'::regclass) " as an autoincrement column in PostgreSQL, or the generation of vieproperty, ediproperty or list should be done according to entities not table information ! This is a major drawback in PostgreSQL because identifiers are not recognized properly.
          Hide
          klawandronic Viorel Andronic added a comment -

          See above

          Show
          klawandronic Viorel Andronic added a comment - See above
          klawandronic Viorel Andronic made changes -
          Resolution Cannot Reproduce Bug [ 5 ]
          Status Resolved [ 5 ] Reopened [ 4 ]
          Hide
          pmuir Pete Muir added a comment -

          Reopening and assigning to Max as this looks like a problem in hibernatetools, not seam-gen (hibernate tools is recognising this as an assigned id and so seam-gen is as well).

          Show
          pmuir Pete Muir added a comment - Reopening and assigning to Max as this looks like a problem in hibernatetools, not seam-gen (hibernate tools is recognising this as an assigned id and so seam-gen is as well).
          pmuir Pete Muir made changes -
          Fix Version/s 2.0.0.GA [ 12311781 ]
          Assignee Pete Muir [ pmuir ] Max Andersen [ maxandersen ]
          Hide
          maxandersen Max Rydahl Andersen added a comment -

          Viorel - if you can tell me how we via jdbc metadata or postgressql specific information can detect that the id is automatically assigned then we can add this support in a postgres specific MetaDataDialect.

          You can see examples of dialects here:
          http://fisheye.jboss.org/browse/Hibernate/branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/dialect

          ...and mysql example at:
          http://fisheye.jboss.org/browse/Hibernate/branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/dialect/MySQLMetaDataDialect.java?r=11422

          Show
          maxandersen Max Rydahl Andersen added a comment - Viorel - if you can tell me how we via jdbc metadata or postgressql specific information can detect that the id is automatically assigned then we can add this support in a postgres specific MetaDataDialect. You can see examples of dialects here: http://fisheye.jboss.org/browse/Hibernate/branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/dialect ...and mysql example at: http://fisheye.jboss.org/browse/Hibernate/branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/dialect/MySQLMetaDataDialect.java?r=11422
          Hide
          klawandronic Viorel Andronic added a comment -

          Hi Max,

          This is a SQL template that tells you when a column has a default value given by a sequence:

          select column_default from information_schema.columns
          where table_catalog='postgres' and table_schema='security' and table_name='group'

          the result is:

          "nextval('"security".group_id_seq'::regclass)"

          you can process this string and identify the keyword: 'nextval' that tells you: BINGO!

          I hope this is helpful

          Show
          klawandronic Viorel Andronic added a comment - Hi Max, This is a SQL template that tells you when a column has a default value given by a sequence: select column_default from information_schema.columns where table_catalog='postgres' and table_schema='security' and table_name='group' the result is: "nextval('"security".group_id_seq'::regclass)" you can process this string and identify the keyword: 'nextval' that tells you: BINGO! I hope this is helpful
          Hide
          klawandronic Viorel Andronic added a comment -

          Actually, the template is an example and it is incomplete, the SQL that produces that result is

          select column_default from information_schema.columns
          where table_catalog='postgres' and table_schema='security' and table_name='group' and column_name='id'

          The template should be easy to identify.

          You can find more on this here:

          http://archives.postgresql.org/pgsql-admin/2003-10/msg00374.php

          Show
          klawandronic Viorel Andronic added a comment - Actually, the template is an example and it is incomplete, the SQL that produces that result is select column_default from information_schema.columns where table_catalog='postgres' and table_schema='security' and table_name='group' and column_name='id' The template should be easy to identify. You can find more on this here: http://archives.postgresql.org/pgsql-admin/2003-10/msg00374.php
          Hide
          pmuir Pete Muir added a comment -

          Viorel, please open an issue Hibernate Tools JIRA (it's not in the same JIRA instance as this, so we can't just move the issue).

          Show
          pmuir Pete Muir added a comment - Viorel, please open an issue Hibernate Tools JIRA (it's not in the same JIRA instance as this, so we can't just move the issue).
          pmuir Pete Muir made changes -
          Status Reopened [ 4 ] Closed [ 6 ]
          Resolution Won't Fix [ 9 ]
          velias Vlastimil Eliáš made changes -
          Workflow jira [ 12354850 ] GIT Pull Request workflow [ 12531724 ]

            People

            • Assignee:
              maxandersen Max Rydahl Andersen
              Reporter:
              klawandronic Viorel Andronic
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development