• Post Reply Bookmark Topic Watch Topic
  • New Topic

ConstraintViolationException in Hibernate  RSS feed

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

I have been struggling to find the root cause of the following error in my application:

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

My Table(DataLayout) in the backend looks:

create table db2admin.datalayout(datalayoutid bigint not null primary key, xslfo varchar(30))

My mapping file looks:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "hibernate-mapping-2.0.dtd">

<class name="com.averitt.DataLayout" table="datalayout">
<id name="id" column="datalayoutid" type="long">
<generator class="assigned">

<property name="xslFO" column="xslfo" type="string"/>

<!-- parsed in 10ms -->

My application code looks:

DataLayout layout = new DataLayout();
Long lon = new Long(1000);
layout.setXslFO("Extensible Style Sheet Language Formatting Objects");
} else if (Class.forName("com.averitt.DataLayout").isInstance(anObject)) {
sess = sessions.openSession();
tx = sess.beginTransaction();


Could anyone have any idea what's going wrong in my code? I also made sure that no duplicate keys nor null values were set to the above object. I am baffled with this error. I appreciate your help.

Haricharan M.
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
looks like the same error (302/22001) as in your other message.
- did you check your mappings and your dialect settings and your table definition ?

some questions and remarks
- why do you cast anObject to DataLayout before calling save ?
- why do you use isInstance() instead of instanceof operator ?
- why do you create a Long first and then call longValue() on it ? try to use nullable values as identifiers with hibernate (also see the hibernate doco)

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!