-->
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.  [ 2 posts ] 
Author Message
 Post subject: Duplicate PK ?
PostPosted: Mon Aug 20, 2007 9:25 am 
Newbie

Joined: Mon Jul 09, 2007 9:32 am
Posts: 17
I have a class Money which has two child classes: Cash, Check.
Code:
   Cash client2usCash = (Cash) c.getBondPaymentMap().get("client2usCash");      
      this.getHibernateTemplate().save(client2usCash);      
      
      Check client2usCheck = (Check) c.getBondPaymentMap().get("client2usCheck");      
      this.getHibernateTemplate().save(client2usCheck);


But the Object has same ID and cause error: Duplicate entry '10' for key 1, two objects have same PK. The error is

Code:
2007-08-19 23:13:05,078 DEBUG [org.hibernate.cache.UpdateTimestampsCache 50] - Pre-invalidating space [mts_money]
2007-08-19 23:13:05,078 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister 2204] - Inserting entity: [data.Cash#10]
2007-08-19 23:13:05,078 DEBUG [org.hibernate.jdbc.AbstractBatcher 44] - Executing batch size: 1
2007-08-19 23:13:05,093 DEBUG [org.hibernate.jdbc.AbstractBatcher 374] - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2007-08-19 23:13:05,093 DEBUG [org.hibernate.jdbc.AbstractBatcher 533] - closing statement
2007-08-19 23:13:05,093 DEBUG [org.hibernate.jdbc.AbstractBatcher 366] - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2007-08-19 23:13:05,093 DEBUG [org.hibernate.SQL 401] - insert into mts_money (amount, payDate, method, empId, customerId, cashOwnInfo, des, moneyId) values (?, ?, ?, ?, ?, ?, 'CASH', ?)
Hibernate: insert into mts_money (amount, payDate, method, empId, customerId, cashOwnInfo, des, moneyId) values (?, ?, ?, ?, ?, ?, 'CASH', ?)
2007-08-19 23:13:05,093 DEBUG [org.hibernate.jdbc.AbstractBatcher 484] - preparing statement
2007-08-19 23:13:05,093 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister 1992] - Dehydrating entity: [data.Cash#10]
2007-08-19 23:13:05,093 DEBUG [org.hibernate.type.StringType 133] - binding '' to parameter: 1
2007-08-19 23:13:05,093 DEBUG [org.hibernate.type.TimestampType 126] - binding null to parameter: 2
2007-08-19 23:13:05,093 DEBUG [org.hibernate.type.StringType 126] - binding null to parameter: 3
2007-08-19 23:13:05,093 DEBUG [org.hibernate.type.StringType 126] - binding null to parameter: 4
2007-08-19 23:13:05,093 DEBUG [org.hibernate.type.StringType 126] - binding null to parameter: 5
2007-08-19 23:13:05,109 DEBUG [org.hibernate.type.StringType 126] - binding null to parameter: 6
2007-08-19 23:13:05,109 DEBUG [org.hibernate.type.LongType 133] - binding '10' to parameter: 7
2007-08-19 23:13:05,109 DEBUG [org.hibernate.cache.UpdateTimestampsCache 50] - Pre-invalidating space [mts_objrel]
2007-08-19 23:13:05,109 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister 2204] - Inserting entity: [data.ObjRel#165]
2007-08-19 23:13:05,109 DEBUG [org.hibernate.jdbc.AbstractBatcher 44] - Executing batch size: 1
2007-08-19 23:13:05,109 DEBUG [org.hibernate.jdbc.AbstractBatcher 374] - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2007-08-19 23:13:05,109 DEBUG [org.hibernate.jdbc.AbstractBatcher 533] - closing statement
2007-08-19 23:13:05,125 DEBUG [org.hibernate.util.JDBCExceptionReporter 69] - Could not execute JDBC batch update [insert into mts_money (amount, payDate, method, empId, customerId, cashOwnInfo, des, moneyId) values (?, ?, ?, ?, ?, ?, 'CASH', ?)]
java.sql.BatchUpdateException: Duplicate entry '10' for key 1
   at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1237)
   at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:936)
   at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
   at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
   at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
   at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2224)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
   at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
   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 org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:575)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:662)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:632)
   at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:314)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:117)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy1.saveNewCase(Unknown Source)
   at controller.MtsActionController.caseHandler(MtsActionController.java:171)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:428)
   at org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:366)
   at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
   at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:857)
   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:792)
   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:475)
   at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:440)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
   at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
   at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
   at java.lang.Thread.run(Unknown Source)

The mapping file is
Code:
<class name="data.Money" table="mts_money">
      <cache usage="read-write"/>      
        <id name="moneyId" unsaved-value="null">
            <generator class="increment"/>
        </id>
        <discriminator column="des" type="string" />
        <property name="amount"/>
        <property name="payDate" type="java.util.Date" />
        <property name="method"/>
        <property name="empId"/>
        <property name="customerId"/>
       
        <subclass name="data.Check" discriminator-value="CHECK">
           <property name="checkNum" />
           <property name="formNum" />                                               
        </subclass>
        <subclass name="data.Cash" discriminator-value="CASH">
           <property name="cashOwnInfo" />                                                            
        </subclass>             
   </class>


Top
 Profile  
 
 Post subject: so what ?
PostPosted: Tue Aug 28, 2007 1:03 pm 
Newbie

Joined: Tue Aug 28, 2007 12:54 pm
Posts: 16
Location: Munich, Germany
Now what is your problem with that ? What did you expect ?

_________________
www.tomeicher.de


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.