Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate SQL Error

 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys! I get this error when I run my application. Could you please tell me what this means?


Exceptions
[java] WARNING: SQL Error: -10, SQLState: 23000
[java] Mar 21, 2007 5:42:27 PM org.hibernate.util.JDBCExceptionReporter l
Exceptions
[java] SEVERE: Attempt to insert null into a non-nullable column: column:
ESSAGE_ID table: MESSAGES in statement [insert into MESSAGES (MESSAGE_ID, NEXT
ESSAGE_ID, MESSAGE_TEXT) values (null, ?, ?)]
[java] Exception in thread "main" org.hibernate.exception.ConstraintViola
onException: could not insert: [hello.Message]
[java] at org.hibernate.exception.SQLStateConverter.convert(SQLStateC
verter.java:71)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExc
tionHelper.java:43)
[java] at org.hibernate.id.insert.AbstractSelectingDelegate.performIn
rt(AbstractSelectingDelegate.java:40)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.inse
(AbstractEntityPersister.java:2154)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.inse
(AbstractEntityPersister.java:2634)
[java] at org.hibernate.action.EntityIdentityInsertAction.execute(Ent
yIdentityInsertAction.java:48)
[java] at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:2
)
[java] at org.hibernate.event.def.AbstractSaveEventListener.performSa
OrReplicate(AbstractSaveEventListener.java:298)
[java] at org.hibernate.event.def.AbstractSaveEventListener.performSa
(AbstractSaveEventListener.java:181)
[java] at org.hibernate.event.def.AbstractSaveEventListener.saveWithG
eratedId(AbstractSaveEventListener.java:107)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.sa
WithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
[java] at org.hibernate.event.def.DefaultSaveEventListener.saveWithGe
ratedOrRequestedId(DefaultSaveEventListener.java:33)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.en
tyIsTransient(DefaultSaveOrUpdateEventListener.java:172)
[java] at org.hibernate.event.def.DefaultSaveEventListener.performSav
rUpdate(DefaultSaveEventListener.java:27)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.on
veOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
[java] at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:53

[java] at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
[java] at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
[java] at hello.HelloWorld.main(Unknown Source)
[java] Caused by: java.sql.SQLException: Attempt to insert null into a no
nullable column: column: MESSAGE_ID table: MESSAGES in statement [insert into
SSAGES (MESSAGE_ID, NEXT_MESSAGE_ID, MESSAGE_TEXT) values (null, ?, ?)]
[java] at org.hsqldb.jdbc.Util.throwError(Unknown Source)
[java] at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown
ource)
[java] at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeU
ate(NewProxyPreparedStatement.java:105)
[java] at org.hibernate.id.insert.AbstractSelectingDelegate.performIn
rt(AbstractSelectingDelegate.java:33)
[java] ... 16 more
[java] Java Result: 1

BUILD SUCCESSFUL



Here is my persistent class



Thanks!
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Caused by: java.sql.SQLException: Attempt to insert null into a no
nullable column: column: MESSAGE_ID table: MESSAGES in statement [insert into
SSAGES (MESSAGE_ID, NEXT_MESSAGE_ID, MESSAGE_TEXT) values (null, ?, ?)]

How are you generating/setting your primary key? You are using the GeneratedValue annotation, which means you are delegating to the database to provide one.However you don't seem to be specifying the generation strategy. Doesn't HSQLDB use sequences? In which case you need to tell Hibernate which sequence to use.
 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul!Thanks for the reply. I actually just started using HSQLDB so I don't know much about it. But if it would help, I just ported from XML to annotations. The XML didn't also work BTW and produces this error:


[java] INFO: building session factory
[java] Mar 21, 2007 6:07:07 PM org.hibernate.impl.SessionFactoryObjectFacto
ry addInstance
[java] INFO: Not binding factory to JNDI, no JNDI name configured
[java] Hibernate:
[java] select
[java] max(MESSAGE_ID)
[java] from
[java] MESSAGES
[java] Hibernate:
[java] insert
[java] into
[java] MESSAGES
[java] (MESSAGE_TEXT, NEXT_MESSAGE_ID, MESSAGE_ID)
[java] values
[java] (?, ?, ?)
[java] Exception in thread "main" java.lang.NoClassDefFoundError: antlr/ANT
LRException
[java] at org.hibernate.hql.ast.ASTQueryTranslatorFactory.createQueryTr
anslator(ASTQueryTranslatorFactory.java:35)
[java] at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.j
ava:74)
[java] at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.j
ava:56)
[java] at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(Que
ryPlanCache.java:72)
[java] at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(Abstra
ctSessionImpl.java:133)
[java] at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSe
ssionImpl.java:112)
[java] at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1
623)
[java] at hello.HelloWorld.main(Unknown Source)
[java] Java Result: 1

BUILD SUCCESSFUL
Total time: 4 seconds


and the XML



I intend to make the ID auto-increment. Could you please tell me how to do this in Hibernate annotation? Thanks!
[ March 21, 2007: Message edited by: Timothy Sam ]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[java] Exception in thread "main" java.lang.NoClassDefFoundError: antlr/ANT
LRException

This means the antlr stuff is missing from your classpath. Check how you have configured this.


I intend to make the ID auto-increment. Could you please tell me how to do this in Hibernate annotation?

You need to specify the strategy attribute of your GeneratedValue annotation using the GenerationType.IDENTITY for hsqldb (I think). If you've defined an IDENTITY column in your DDL Hibernate will just defer to hsqldb to assign a primary key.
 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! I tried both your suggestions and the first one worked, the second one... I'm just not too sure because another error appeared. Anyway, I guess I should stick with the xml mapping first before jumping to annotations. Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic