Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Could not synchronize database state with session

 
Haricharan Maramraj
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone:

Could anyone tell me why I could save an object from java with the help of Hibernate? I am getting the following error message:

Dec 27 15:42:41 ERROR {JDBCExceptionReporter.java:58} - DB2 SQL error: SQLCODE: -302, SQLSTATE: 22001, SQLERRMC: null
Dec 27 15:42:41 ERROR {SessionImpl.java:2399} - Could not synchronize database state with session
net.sf.hibernate.exception.ConstraintViolationException: could not insert: [com.averitt.DataLayout#1000]
at net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:63)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:30)
at net.sf.hibernate.persister.AbstractEntityPersister.convert(AbstractEntityPersister.java:1332)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:474)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:438)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:37)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2438)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2391)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2260)
at com.averitt.EventManager.testCreateAndRead(EventManager.java:294)
at com.averitt.EventManager.setUp(EventManager.java:195)
at com.averitt.EventManager.main(EventManager.java:307)
Caused by: com.ibm.db2.jcc.b.SqlException: DB2 SQL error: SQLCODE: -302, SQLSTATE: 22001, SQLERRMC: null

There is nothing complicated in my class except few getters and setters. And the corresponding table in DB2 has id which is not null and primary key. I also made sure that I am passing ID which is unique and not null while saving the object.

I appreciate your time and effort.

Thankyou
Haricharan M.
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i can not tell from just the exception. can you show the mapping, the object you want to insert and the code where you insert the object ?


pascal
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok.... i found a hint on this page

the error code means:
Conversion error on input host variable &2;

so perhaps you are mapping to the wrong datatype ?
is your DB Dialect set correct in hibernate properties ?

pascal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic