14 Replies Latest reply on Oct 13, 2007 5:31 AM by maxandersen

    seam generate-entities failure

    jwooten

      I have a simple database table queue that has a String name, and two
      int columns, NEXT_ENTRY, and ENTRY_INC;



      When I did seam generate-entities, it created the following and then fails when trying to fetch the list of entries. It fails thinking the NEXT_ENTRY is a small blob or such. Shouldn't this be easy for Seam? It's a MySQL database and very small, etc.

      Following generated by seam generate-entities
      The name in the table is a string and the other two entries
      are ints, like 9050, and 10 ( this is in MySQL )

      It trys to treat them as Serializeable and fails somehow.
      How do I change this to use integers (i.e. provide the correct mapping)? I would think this would be straightforward for this simple table.

      package com.shoulderscorp.queuedb;
      // Generated Oct 1, 2007 4:04:08 PM by Hibernate Tools 3.2.0.b9

      import java.io.Serializable;
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.Id;
      import javax.persistence.Table;
      import org.hibernate.validator.Length;
      import org.hibernate.validator.NotNull;

      /**
      * Queue generated by hbm2java
      */
      @Entity
      @Table(name = "queue", catalog = "queue_db")
      public class Queue implements java.io.Serializable {

      private String name;
      private Serializable nextEntry;
      private Serializable entryIncr;

      public Queue() {
      }

      public Queue(String name, Serializable nextEntry, Serializable entryIncr) {
      this.name = name;
      this.nextEntry = nextEntry;
      this.entryIncr = entryIncr;
      }

      @Id
      @Column(name = "NAME", unique = true, nullable = false, length = 32)
      @NotNull
      @Length(max = 32)
      public String getName() {
      return this.name;
      }

      public void setName(String name) {
      this.name = name;
      }

      @Column(name = "NEXT_ENTRY", nullable = false)
      @NotNull
      public Serializable getNextEntry() {
      return this.nextEntry;
      }

      public void setNextEntry(Serializable nextEntry) {
      this.nextEntry = nextEntry;
      }

      @Column(name = "ENTRY_INCR", nullable = false)
      @NotNull
      public Serializable getEntryIncr() {
      return this.entryIncr;
      }

      public void setEntryIncr(Serializable entryIncr) {
      this.entryIncr = entryIncr;
      }

      }

        • 1. Re: seam generate-entities failure
          maxandersen

          what is the DDL for that table ?

          apparently mysql is not returning a sql type that we have mapped.

          to workaround it you can adjust the reveng.xml file to include mappings from the column type to the relevant hibernate type you actually want.

          (see tools.hibernate.org for docs about reveng.xml)

          • 2. Re: seam generate-entities failure
            jwooten

            This is what I get for the table queue in question.

            mysql> describe queue;
            +------------+-----------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +------------+-----------------+------+-----+---------+-------+
            | NAME | varchar(32) | NO | PRI | DEFAULT | |
            | NEXT_ENTRY | int(7) unsigned | NO | | 0 | |
            | ENTRY_INCR | int(7) unsigned | NO | | 10 | |
            +------------+-----------------+------+-----+---------+-------+
            3 rows in set (0.09 sec)

            • 3. Re: seam generate-entities failure
              jwooten

              Why would Seam not provide a mapping for int? It's not an odd or unusual mapping? It's mapping it as a small blob it says.

              I read the part about the xml file and changing it, but there wasn't much to go on there.

              Is this seam generation portion ready for use or is it a "beta" edition? I really wanted to use it to create some maintenance screens for a lot of tables we use in applications.

              • 4. Re: seam generate-entities failure
                pmuir

                seam-gen is a tool for quickly bootstrapping an application - it's not supposed to generate code you put straight into production.

                • 5. Re: seam generate-entities failure
                  franciscoacb

                   

                  "pete.muir@jboss.org" wrote:
                  seam-gen is a tool for quickly bootstrapping an application - it's not supposed to generate code you put straight into production.


                  Why not, Pete?

                  I mean, I have always thinked that seam-gen generated code was what is suggested by JBoss Seam Team as a "good pratice", a good way to organize code etc.

                  You guys have a huge experience in developing web applications, infinitely greater than mine, as a newbie. So isn't it correct to assume that the generated code takes advantage of this experience and we can consider that the code is already (or at least almost) production-quality?

                  Cheers,
                  Francisco Antônio
                  "The biggest weapon against stress is our ability to choose a thought instead of another one." (WILLIAM JAMES)"

                  • 6. Re: seam generate-entities failure
                    jwooten

                    I didn't expect it to create my application, but to give me the starting point for a series of maintenance screens for a lot of tables we use in the applicaiton.

                    • 7. Re: seam generate-entities failure
                      pmuir

                       

                      "franciscoacb" wrote:
                      Why not, Pete?


                      I would never ever put generated code into production without a complete review first. This just seems like common sense to me.

                      I mean, I have always thinked that seam-gen generated code was what is suggested by JBoss Seam Team as a "good pratice", a good way to organize code etc.


                      Sure, but its also auto generated - so the templates are best on our recommendations - but not the resulting app.

                      You guys have a huge experience in developing web applications, infinitely greater than mine, as a newbie. So isn't it correct to assume that the generated code takes advantage of this experience and we can consider that the code is already (or at least almost) production-quality?


                      I would call it always a good starting point for your app - something that you can review, add to and play around with.

                      • 8. Re: seam generate-entities failure
                        pmuir

                        As Max says - mysql is probably returning some odd information about the column. I don't think int(7) is the default size for an int?

                        • 9. Re: seam generate-entities failure
                          jwooten

                          int(7) is what you get if you do the default int assignment. At least in my case it was.

                          • 10. Re: seam generate-entities failure
                            pmuir

                            Oops, sorry :(

                            Anyway, you should report this on the hibernatetools forum

                            • 11. Re: seam generate-entities failure
                              jwooten

                              The point of my question is not whether it is the appropriate tool to use to generate an application or to just get the initial generated start to that application, but rather that it should at least generate correct code for normal column attributes from mysql! If it only works for one particular demo case, then just state that this is just a tool for doing cute demos, but is not intended to work for anything else but this cute demo we rigged up.

                              Don't try this for anything else, because it won't work and isn't intended to?

                              • 12. Re: seam generate-entities failure
                                jwooten

                                I don't find a hibernate tools forum in the list of forums for this site.

                                Where is it?

                                • 13. Re: seam generate-entities failure
                                  pmuir
                                  • 14. Re: seam generate-entities failure
                                    maxandersen

                                    wo37830: this is just because of some weird datatype being returned by mysql driver/db...we just need to find out what type it is and we can add a mapping for it.

                                    But raise it in hibernatetools forum as pete suggests.