Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hello everybody!
I'm trying to migrate my app from MySql to MS SQL Server 2000.
I'm using Hibernate 2.1, spring 1.1.5
I tried with Microsoft and JTDS drivers and had the same result.
I also tried with “unsaved-value=null” for the id
and have just tried with an id od type Integer and primitive int…
without success!!!
Everything works fine but inserting new rows.
My mapping file follows:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="it.seceti.coc.model.EventoUnrae"
table="EventoUNRAE"
dynamic-update="false"
dynamic-insert="true"
>
<id name="id"
column="id"
type="java.lang.Long"
unsaved-value="0"
>
<generator class="native"/>
</id>
<property
name="comumnName"
type="java.lang.String"
update="true"
insert="true"
access="property"
column=" comumnName "
length="40"
/>
...
</class>
</hibernate-mapping>
It seems the database can’t initialize the id
while the row is being inserted and does’t accept the unsaved-value=0.
I get the following error executing the method getHibernateTemplate().saveOrUpdate(myObject).
[junit] org.springframework.dao.DataIntegrityViolationException: (Hibernate
operation): data integrity violated by SQL ''; nested exception is java.sql.SQLE
xception: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]String or binary
data would be truncated.
[junit] java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][S
QLServer]String or binary data would be truncated.
[junit] at com.microsoft.jdbc.base.BaseExceptions.createException(Unknow
n Source)
[junit] at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown S
ource)
[junit] at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken
(Unknown Source)
[junit] at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken
(Unknown Source)
[junit] at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyTo
ken(Unknown Source)
[junit] at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unkn
own Source)
[junit] at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextRe
sultType(Unknown Source)
[junit] at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState
(Unknown Source)
[junit] at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown
Source)
[junit] at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute
(Unknown Source)
[junit] at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown S
ource)
[junit] at com.microsoft.jdbc.base.BaseStatement.executeInternal(Unknown
Source)
[junit] at com.microsoft.jdbc.base.BasePreparedStatement.execute(Unknown
Source)
[junit] at net.sf.hibernate.persister.EntityPersister.insert(EntityPersi
ster.java:508)
[junit] at net.sf.hibernate.persister.EntityPersister.insert(EntityPersi
ster.java:429)
[junit] at net.sf.hibernate.impl.ScheduledIdentityInsertion.execute(Sche
duledIdentityInsertion.java:29)
[junit] at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:932
)
[junit] at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:857
)
[junit] at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier
(SessionImpl.java:775)
[junit] at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
[junit] at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.ja
va:1388)
[junit] at org.springframework.orm.hibernate.HibernateTemplate$16.doInHi
bernate(HibernateTemplate.java:532)
[junit] at org.springframework.orm.hibernate.HibernateTemplate.execute(H
ibernateTemplate.java:312)
[junit] at org.springframework.orm.hibernate.HibernateTemplate.saveOrUpd
ate(HibernateTemplate.java:529)
[junit] at it.seceti.coc.dao.hibernate.EventoUnraeDAOHibernate.saveEvent
o(EventoUnraeDAOHibernate.java:139)
[junit] at it.seceti.coc.service.commands.local.UnraeSaveEventoUnraeComm
and.doExecute(UnraeSaveEventoUnraeCommand.java:35)
[junit] at it.seceti.coc.service.command.local.LocalCommandManager.doExe
cute(LocalCommandManager.java:29)
[junit] at it.seceti.coc.service.ws.impl.EventoUnraeSaveSimulateImpl.sav
eEventoUnrae(EventoUnraeSaveSimulateImpl.java:20)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcces
sorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMet
hodAccessorImpl.java:25)
[junit] at java.lang.reflect.Method.invoke(Method.java:324)
[junit] at org.springframework.aop.support.AopUtils.invokeJoinpointUsing
Reflection(AopUtils.java:282)
[junit] at org.springframework.aop.framework.ReflectiveMethodInvocation.
invokeJoinpoint(ReflectiveMethodInvocation.java:155)
[junit] at org.springframework.aop.framework.ReflectiveMethodInvocation.
proceed(ReflectiveMethodInvocation.java:122)
[junit] at org.springframework.transaction.interceptor.TransactionInterc
eptor.invoke(TransactionInterceptor.java:56)
[junit] at org.springframework.aop.framework.ReflectiveMethodInvocation.
proceed(ReflectiveMethodInvocation.java:144)
[junit] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(J
dkDynamicAopProxy.java:174)
[junit] at $Proxy3.saveEventoUnrae(Unknown Source)
[junit] at it.seceti.coc.service.atomictests.backend.EventoUnraeSaveAtom
ic.testSave(EventoUnraeSaveAtomic.java:20)
[junit] at it.seceti.coc.service.ws.EventoUnraeSaveTest.testRemoveEvento
Unrae(EventoUnraeSaveTest.java:27)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcces
sorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMet
hodAccessorImpl.java:25)
[junit] at java.lang.reflect.Method.invoke(Method.java:324)
[junit] at junit.framework.TestCase.runTest(TestCase.java:154)
[junit] at junit.framework.TestCase.runBare(TestCase.java:127)
[junit] at junit.framework.TestResult$1.protect(TestResult.java:106)
[junit] at junit.framework.TestResult.runProtected(TestResult.java:124)
[junit] at junit.framework.TestResult.run(TestResult.java:109)
[junit] at junit.framework.TestCase.run(TestCase.java:118)
[junit] at junit.framework.TestSuite.runTest(TestSuite.java:208)
[junit] at junit.framework.TestSuite.run(TestSuite.java:203)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.
run(JUnitTestRunner.java:289)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.
launch(JUnitTestRunner.java:656)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.
main(JUnitTestRunner.java:558)
[junit] ------------- ---------------- ---------------
[junit] Testcase: testRemoveEventoUnrae(it.seceti.coc.service.ws.EventoUnrae
SaveTest): Caused an ERROR
[junit] null id in entry (don't flush the Session after an exception occurs)
[junit] net.sf.hibernate.AssertionFailure: null id in entry (don't flush the
Session after an exception occurs)
[junit] at net.sf.hibernate.impl.SessionImpl.checkId(SessionImpl.java:26
41)
[junit] at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.jav
a:2465)
[junit] at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.j
ava:2458)
[junit] at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl
.java:2260)
[junit] at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2239
)
[junit] at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTrans
action.java:61)
[junit] at org.springframework.orm.hibernate.HibernateTransactionManager
.doCommit(HibernateTransactionManager.java:472)
[junit] at org.springframework.transaction.support.AbstractPlatformTrans
actionManager.commit(AbstractPlatformTransactionManager.java:377)
[junit] at org.springframework.transaction.interceptor.TransactionAspect
Support.doCommitTransactionAfterReturning(TransactionAspectSupport.java:243)
[junit] at org.springframework.transaction.interceptor.TransactionInterc
eptor.invoke(TransactionInterceptor.java:66)
[junit] at org.springframework.aop.framework.ReflectiveMethodInvocation.
proceed(ReflectiveMethodInvocation.java:144)
[junit] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(J
dkDynamicAopProxy.java:174)
[junit] at $Proxy3.saveEventoUnrae(Unknown Source)
[junit] at it.seceti.coc.service.atomictests.backend.EventoUnraeSaveAtom
ic.testSave(EventoUnraeSaveAtomic.java:20)
[junit] at it.seceti.coc.service.ws.EventoUnraeSaveTest.testRemoveEvento
Unrae(EventoUnraeSaveTest.java:27)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcces
sorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMet
hodAccessorImpl.java:25)
Any help would be appreciated.
Thanks a lot!
Lucia