net.sf.hibernate.JDBCException: could not insert: [test.ABusinessObject]

Hibernate JIRA | Grainne Coghlan | 1 decade ago
  1. 0

    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)

    Hibernate JIRA | 1 decade ago | Grainne Coghlan
    net.sf.hibernate.JDBCException: could not insert: [test.ABusinessObject]
  2. 0

    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)

    Hibernate JIRA | 1 decade ago | Grainne Coghlan
    net.sf.hibernate.JDBCException: could not insert: [test.ABusinessObject]
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    Hibernate Community • View topic - problem building caveatemptor with firebird 1.5 ss

    hibernate.org | 1 year ago
    net.sf.hibernate.JDBCException: could not insert: [org.hibernate.auction.model.Category#1]
  5. 0

    oracle - hibernate

    wsabi4axis | 1 decade ago | nobody
    net.sf.hibernate.JDBCException: could not insert: \[org.allesta.wsabi.monitor.log.model.AuditLogDetail\#b19791b705bbe8d60105bbe922e70002\]

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. net.sf.hibernate.JDBCException

      could not insert: [test.ABusinessObject]

      at net.sf.hibernate.persister.EntityPersister.insert()
    2. net.sf.hibernate
      SessionImpl.save
      1. net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:541)
      2. net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:433)
      3. net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:876)
      4. net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:817)
      5. net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:737)
      6. net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:717)
      6 frames
    3. test
      TestABusinessObject.testABusinessObject
      1. test.TestABusinessObject.testABusinessObject(TestABusinessObject.java:29)
      1 frame