-->
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.  [ 5 posts ] 
Author Message
 Post subject: does Hibernate support boolean to integer conversion?
PostPosted: Wed May 30, 2007 6:02 am 
Newbie

Joined: Wed May 30, 2007 5:33 am
Posts: 2
Hi,

I have a Java class that has some boolean fields and they are mapped as integers in PostgreSQL. Now when I try to read records from the DB using Hibernate, it does the automatic conversion from integer to boolean. But when I try to insert the record, I get following error::

Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.genuitec.hibernate.UserDAO.save(UserDAO.java:31)
at maze.test.test.main(test.java:25)
Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into public.user (name, flag, id) values (chintan, 1, 1) was aborted. Call getNextException to see the cause.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2530)
at org.postgresql.core.v3.QueryExecutorImpl$1.handleError(QueryExecutorImpl.java:402)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1317)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:350)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2592)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
... 9 more


So my question is does Hibernate not support automatic conversion from boolean to integer?

Thanks for your help,
Medha


Top
 Profile  
 
 Post subject: does Hibernate support boolean to integer conversion?
PostPosted: Wed May 30, 2007 12:26 pm 
Beginner
Beginner

Joined: Wed Apr 18, 2007 6:17 pm
Posts: 49
Location: Dominican Republic
There is a property to substitute a value for other value, the property is called hibernate.query.substitutions. See session 3.5. Optional configuration properties on the hibernate reference, if it helps rate the post

regards,


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 5:47 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
mbhatt,

Is your datatype a Boolean or a boolean? I found with Oracle that if it was Boolean and you were saving multiple records and some were null and some were not null then the same type of error would occur.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 6:52 am 
Newbie

Joined: Wed May 30, 2007 5:33 am
Posts: 2
My datatype is boolean.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 2:47 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
You can turn on the show sql property and see what the insert is firing off.

To see the actual values being set you'll have to turn on the hibernate logging as well.

I wouldn't think you would have to do the query substitution property but I guess it all depends on how you are trying to insert your record.

Seeing the code might help.


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

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.