Uploaded image for project: 'z - Hibernate 2'
  1. HB-669

Sybase dialect is broken for table with just an identity column

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.1.1
    • Fix Version/s: 3.0 alpha
    • Component/s: core
    • Labels:
      None
    • Environment:
      Hibernate version 2.1.1
      Sysbase : Adaptive Server Enterprise/12.5.0.3
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true

      Description

      When experimenting with defining id's and using the 'identity' generator I noticed that the sybase mapping is broken if the class only has an id column.
      When saving such a class the SQL:
      insert into ABusinessObject DEFAULT VALUES
      is produced.
      I think that this should be :
      insert into ABusinessObject values ( )

      The fix would be to delete the method getNoColumnsInsertString in the class net.sf.hibernate.dialect.SybaseDialect.
      This overrides the method in net.sf.hibernate.dialect.Dialect which looks to me like it (Dialect) produces the correct SQL.

      This is an usual case - I don't think it would be likely that I will need to persist a class that only has an id/identity.
      The SQL is fine if there is at least one property defined for the class.

      Below is I hope enough details to reproduce the (minor) problem.

      Consider the following mapping
      <hibernate-mapping>
      <class name="test.ABusinessObject" table="ABusinessObject">
      <id name="id" type="integer" unsaved-value="null">
      <column name="id" sql-type="numeric(10,0)"/>
      <generator class="identity"/>
      </id>
      </class>
      </hibernate-mapping>

      The test.ABusinessObject class:
      public class ABusinessObject {
      private Integer id;
      public Integer getId()

      { return id; }

      public void setId(Integer id)

      { this.id = id; }

      }

      In my test code I have:
      Session session = // ... open session
      ABusinessObject aBusinessObject = new ABusinessObject();
      session.save(aBusinessObject);

      At the point of save with the above mapping the log shows (I have log priority set to debug, and flagged to echo sql is on):

      Hibernate: insert into ABusinessObject DEFAULT VALUES
      09:35:09,622 WARN JDBCExceptionReporter:38 - SQL Error: 156, SQLState: ZZZZZ
      09:35:09,632 ERROR JDBCExceptionReporter:46 - Incorrect syntax near the keyword 'DEFAULT'.

      and the following exception occurs:
      net.sf.hibernate.JDBCException: could not insert: [test.ABusinessObject]
      at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:541)
      at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:433)
      at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:876)
      at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:817)
      at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:737)
      at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:717)
      at test.TestABusinessObject.testABusinessObject(TestABusinessObject.java:29)

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: