-->
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: Problem while loading, updating and deleting records
PostPosted: Sun Dec 13, 2009 12:57 pm 
Newbie

Joined: Sun Dec 13, 2009 10:50 am
Posts: 1
Hi All!


I m developing springs/hibernates/dao using application. I am using "Hibernate Templates" working with DAO.
I m having problem with update delete and select operations with DataBase. I tested many ways but nothing for. Even I m wondering whether I have implemented them right.

Details of the problemm is as follows:


One instance in it is, I have one table having following structure.
create table tbl_pink_test (
userId varchar(10) not null,
date_time datetime not null,
userSs varchar(20) not null
)

applicationContext.xml extract-------------

<bean id="pinkLogssFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="pnkDataSource" />
<property name="mappingResources">
<value>pnk/web/app/ss/res/PinkEtslSsX.hbm.xml</value>
</property>
<property name="hibernateProperties">
<value>hibernate.dialect=org.hibernate.dialect.HSQLDialect</value>
</property>
</bean>
<bean id="pinkSsZoneB" class="pnk.web.app.ss.model.pzone.PinkssZoneDAOImpl">
<property name="sessionFactory" ref="pinkLogssFactory"/>
</bean>

public class PinkssZoneDAOImpl extends HibernateDaoSupport implements BillingPinkssZoneChargingI {

public Collection loadMyZoneDetails(String ani) throws DataAccessException, Exception {
//System.out.println("Fetched "+lst);
Collection lst = this.getHibernateTemplate().find("from PinkssZoneObj pp where pp.userId=? order by pp.pinkssDate DESC", ani);
System.out.println("Fetched all pinkss zone Dtls " + lst);
return lst;
}

public Collection loadMyZoneSongDetails(String userss, String usrId) throws DataAccessException, Exception {
//System.out.println("Fetched "+lst);
Object[] ss = new Object[]{userId, userss};
Collection lst = this.getHibernateTemplate().find("from PinkssZoneObj pp where pp.userId=? and pp.UserSs=?", ss);
System.out.println("Fetched pinkss zone Dtls 4r songId " + lst);
return lst;
}

public String insertMyZoneDetails(PinkssZoneObj updtDao) throws DataAccessException, Throwable, Exception {
//System.out.println("Fetched "+lst);
Serializable ss = this.getHibernateTemplate().save(updtDao);
//System.out.println("Inserted pinkss zone Dtls " + ss);
return String.valueOf(ss);
}

public int updateMyZoneDetails(PinkssZoneObj updtDao) throws DataAccessException, Exception {
System.out.println("Updating " + updtDao.getUserId() + " details of pinkss zone");
int insrtUpdtStts = 0;
this.getHibernateTemplate().saveOrUpdate(updtDao);
insrtUpdtStts = 1;
System.out.println("Updated user Dtls " + insrtUpdtStts);
return insrtUpdtStts;
}

public int deleteMyZoneDetails(PinkssZoneObj updtDao) throws DataAccessException, Exception {
System.out.println("Deleting " + updtDao.getUserId());
int insrtUpdtStts = 0;
this.getHibernateTemplate().delete(updtDao);
insrtUpdtStts = 1;
System.out.println("Deleted user Dtls " + insrtUpdtStts);
return insrtUpdtStts;
}
}

The problem is there are 3 records for userId=1007 and 2 for userId=1001. I used above implementation as code given below. After loading details (for userId=1007) It shows me the correct count of extracted rows, i.e. 3 but when I Iterates through them I found them all same.
I mean all 3 record objects have same userSs value, instead they must be different, as in DB.

Collection usrPZoneDtls = daoPinkZoneBean.loadMyZoneDetails(ani);
List s = (List) usrPZoneDtls;
System.out.println("User records fetched as " + s.size());
out.println(respMyzneLength + s.size() + ";");
if (s.size() >= 1) {
for (int aa = 0; aa <= s.size() - 1; aa++) {
PinkssZoneObj epusznObjTmp = (PinkssZoneObj) s.get(aa);
System.out.println(aa + ") Loaded Zone dtls 4r ["+epusznObjTmp.getUserId()+"] [" + epusznObjTmp.getUserSs().trim());
out.println(respMyzneArr+aa+"]='" + epusznObjTmp.getUserId() + "';");
}
} else {
System.out.println("User not found in DB!! handle it!!:)");
}

Moreover, a problem with update process is also there. I find the record, to be updated, using above method:
loadMyZoneSongDetails("1007", "subsc");
and updated the field using objects method:
updtDao.setUserSs("SOLOROMP");
and I called
updateMyZoneDetails(updtDao);
to update it further. Now it update all 3 records. why It updates all records for userId=1007 with the updated value for userSs of the object I find before.

Another problem is with delete operation. Below is the code used for delete operation:

Collection usrPZoneDtls = daoPinkZoneBean.loadMyZoneDetails("1001", userss);
List s = (List) usrPZoneDtls;
System.out.println("User records fetched as " + s.size());
if (s.size() >= 1) {
PinkssZoneObj epusznObjTmp = (PinkssZoneObj) s.get(aa);
System.out.println("Loaded Zone dtls 4r [" + epusznObj.getUserId() + " having val: " + epusznObj.getUserSs());
int insrtDurrBal = daoPinkZoneBean.deleteMyZoneDetails(epusznObj);
System.out.println("Song details removed Succ!! " + insrtDurrBal);
out.println(insrtDurrBal);
} else {
out.println(respMyzneStatus + "2;");
}

Now, Instead of deleting selected / passed objects row from table, among 2 records, It deletes all 2 records corresponding to user 1001 from DB, and throws exception as given below:

Fetched pinkss zone Dtls 4r songId [pnk.web.app.ss.model.mobradio.obj.PinkssZoneObj@ba007e]
User records fetched as 1
Loaded Zone dtls 4r [1001] having val: SUBSC
Deleting 1001
Dec 12, 2009 5:31:34 PM org.hibernate.jdbc.BatchingBatcher doExecuteBatch
SEVERE: Exception executing batch:
org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 2; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:71)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:68)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:144)
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.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:791)
at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:787)
at pnk.web.app.ss.model.mobradio.pzone.BillingPinkssZoneChargingImpl.deleteMyZoneDetails(BillingPinkssZoneChargingImpl.java:75)
at pnk.web.app.ss.controller.mobradio.subsc.PinkssZoneDao.processRequest(PinkssZoneDao.java:197)
at pnk.web.app.ss.controller.mobradio.subsc.PinkssZoneDao.doGet(PinkssZoneDao.java:269)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Dec 12, 2009 5:31:34 PM org.hibernate.event.def.AbstractFlushingEventListener performExecutions
SEVERE: Could not synchronize database state with session
org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 2; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:71)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:68)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:144)
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.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:791)
at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:787)
at pnk.web.app.ss.model.mobradio.pzone.BillingPinkssZoneChargingImpl.deleteMyZoneDetails(BillingPinkssZoneChargingImpl.java:75)
at pnk.web.app.ss.controller.mobradio.subsc.PinkssZoneDao.processRequest(PinkssZoneDao.java:197)
at pnk.web.app.ss.controller.mobradio.subsc.PinkssZoneDao.doGet(PinkssZoneDao.java:269)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
DataAccessException caught while preparing data 4r 9218588605:: org.springframework.orm.hibernate3.HibernateSystemException: Batch update returned unexpected row count from update [0]; actual row count: 2; expected: 1; nested exception is org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 2; expected: 1


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.