Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.2.1 GA
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Caused by: java.sql.BatchUpdateException: Data truncated for column 'BANK_ID' at row 1
at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:647)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
... 18 more
Name and version of the database you are using:
MYSQL Server 1.2.2
The generated SQL (show_sql=true):
Hibernate: insert into BANK (BANK_NAME, BANK_CODE, LCOUNT, BANK_ID) values (?, ?, ?, ?)
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html
I have recently started using Hibernate. I have managed to get everything to work. I made a small change so that the one of the DAO's primary key is of type DAOPrimary key from Long. DAOPrimary is simply a Integer wrapper class. The problem is when i try to do a save i get the following error
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
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:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at dao.HibernateDAOBase.commit(HibernateDAOBase.java:116)
at dao.HibernateDAOBase.persist(HibernateDAOBase.java:17)
at dao.HibernateDAOBase.save(HibernateDAOBase.java:30)
at hib.client.HibernateClient.save(HibernateClient.java:112)
at hib.client.HibernateClient.<init>(HibernateClient.java:29)
at hib.client.HibernateClient.main(HibernateClient.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: java.sql.BatchUpdateException: Data truncated for column 'BANK_ID' at row 1
at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:647)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
... 18 more
The code from the xml is as so
<id name="primaryKey" type="dao.DAOPrimaryKey">
<column name="BANK_ID" sql-type="NUMERIC" not-null="true"/>
<generator class="dao.TableIDGenerator">
<param name="TABLE_NAME">BANK</param>
<param name="COLUMN_NAME">BANK_ID</param>
</generator>
</id>
The TableIDGenerator class returns an ID of type DAOPrimaryKey, which is being persisted directly, I believe this should be converted into an SQLType.
If i configure TableIDGenerator to return a Long, Int, or Double everything works fine.
In IBatis for example you have Type Handlers which allows you to convert Custom objects into SQL Types.
Thanks in Advance[/i]