5 Replies Latest reply on Aug 6, 2009 6:16 AM by asookazian

    seam-gen reverse engineering SQL Server question

    mdesignz

      Hello,
      I'm using seam-gen (2.2.0.GA) to generate the model from a MS SQL Server 2008 database.  It is a terrific time-saver, but I'm having an issue with Date and DateTime (timestamp) fields.  It generates the datetime (timestamp) fields correctly, but uses java.io.Serializable as the type for Date fields.  I can do a simple search / replace to fix that, but it also doesn't add the @Temporal(TemporalType.DATE) which is a very time-consuming problem to fix considering the database has about 200 tables in it.   It does add the correct annotation for timestamp fields.  I've tried playing with the seam-gen.reveng.xml configuration without success, and was hoping someone has run into this issue and solved it.   Thanks.

        • 1. Re: seam-gen reverse engineering SQL Server question
          asookazian

          I haven't had this problem with SQL SERVER 2005 and Seam 2.x revengr via seam-gen (hbm2java).


          example:


               @Temporal(TemporalType.TIMESTAMP)
               @Column(name = "AddedDate", nullable = false, length = 23)
               @NotNull
               public Date getAddedDate() {
                    return this.addedDate;
               }



          The metadata that hbm2java aquires for the db schema is based on whatever info comes from the jdbc driver.  What jdbc driver and what version of that driver are you using?


          I doubt you would need to do any custom config to get the annotations to be placed correctly in your entity classes.  Otherwise, smells like a bug?

          • 2. Re: seam-gen reverse engineering SQL Server question
            mdesignz

            Thanks for the reply!  I'm using MS' driver (sqljdbc4) and it gets the datetime (timestamp) values correctly.  It's the Date only fields that it types to io.Serializable. I'm not a big SQL Server fan, so I don't have a lot of experience with it.  Are there other jdbc drivers that play nicely with SQL Server (I haven't Googled that yet, but I will).

            • 3. Re: seam-gen reverse engineering SQL Server question
              mdesignz

              I neglected to post the exammple.  Here's what Seam-Gen creates for a Date defined field:




              @Column(name = "insurance_begins_date")
              public Serializable getInsuranceBeginsDate() {
                 return this.insuranceBeginsDate;
              }
              




              And this is what it generates for a datetime (timestamp) field:




              @Temporal(TemporalType.TIMESTAMP)
              @Column(name = "update_date", length = 23)
              public Date getUpdateDate() {
                 return this.updateDate;
              }
              



              • 4. Re: seam-gen reverse engineering SQL Server question
                kapitanpetko

                Robert Morse wrote on Aug 06, 2009 02:04:


                Are there other jdbc drivers that play nicely with SQL Server (I haven't Googled that yet, but I will).



                Try JTDS. Works great and is said to be much faster than the MS driver.

                • 5. Re: seam-gen reverse engineering SQL Server question
                  asookazian

                  You need to post this question on the hibernate forum or JBoss Tools forum b/c seam-gen uses Hibernate Tools (in this case hbm2java specifically) to do the revengr for you.  This actually has nothing to do with Seam.


                  You may be able to specify some override for the Date fields in the seam-gen.reveng.xml so that it doesn't specify Serializable as the return type.  IMO it is very strange that it's doing that.  If that's java.io.Serializable, that is a marker interface, and is not supposed to be return by any method ever.


                  Read this as well:  http://www.redhat.com/docs/en-US/JBoss_Developer_Studio/en/hibernatetools/html/codegen.html


                  As far as jTDS is concerned, never used it but on that web site itself it states it passes J2EE 1.3 certification.  That's very old.  But give it a shot to see what happens.


                  The other option is to refactor your Date columns to datetime type in your SQL SERVER tables.


                  There's a sqljdbc.jar which is version 2.0 that was released 04/2009.  Try that one if you don't already have it.


                  http://www.microsoft.com/downloads/details.aspx?FamilyID=99b21b65-e98f-4a61-b811-19912601fdc9&displaylang=en