Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

Could not synchronize database state with session

 
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.
 
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
 
I suggest huckleberry pie. But the only thing on the gluten free menu is this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!