• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ConstraintViolationException in Hibernate

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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">

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

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

</hibernate-mapping>
<!-- parsed in 10ms -->

My application code looks:

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

sess.save((DataLayout)anObject);

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.


Thankyou
Haricharan M.
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)

pascal
 
Don't touch me. And dont' touch this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic