-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Data Truncation Exception doesn't print column name
PostPosted: Sat Sep 28, 2013 7:09 am 
Newbie

Joined: Sat Jan 22, 2011 2:56 am
Posts: 5
I'm using Hibernate 3.0 with SQL Server 2008.

My problem is whenever a Data Truncation exception occurs, it doesn't show column name, which causes this exception. Neither it shows the query being fired with actual values.

For example, I have the following POJO:

Teacher.java
Code:
    private long id;
    private String name;
   
    // getter-setter of both


name field is mapped to name column.

name column is having datatype: varchar(50).

Now if I try to add a record of Teacher with name having a String containing more than 50 characters (session.save(teacher)), it gives me the following exception:

Code:
    org.hibernate.exception.DataException: could not insert: [com.test.Teacher]
       at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:102)
       at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
       at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:64)
       at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2329)
       at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2836)
       at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
       at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:267)
       at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
       at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
       at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
       at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
       at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
       at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
       at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
       at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:677)
       at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:669)
       at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:665)
       at com.test.TestTeacher.main(TestTeacher.java:1314)
    Caused by: java.sql.DataTruncation: Data truncation
       at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:382)
       at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2820)
       at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2258)
       at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:632)
       at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:584)
       at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:546)
       at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:504)
       at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:147)
       at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94)
       at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)
       ... 16 more

As you can see, the above exception doesn't give any kind of information related to column or to data being entered.

I've found the following link: http://www.cereslogic.com/pages/2008/06/10/use-hibernate-validators-to-find-nasty/

But it uses annotations. I'm not using annotations but mapping files.

I've also tried handling the exception & the following:
Code:
    dataTruncation.getIndex();
    dataTruncation.getDataSize();
    dataTruncation.getTransferSize();


But those also don't help, as they all return -1.

Can someone suggest me a suitable way around?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.