-->
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.  [ 6 posts ] 
Author Message
 Post subject: Hibernate won't delete rows?
PostPosted: Thu Aug 25, 2005 3:59 pm 
Beginner
Beginner

Joined: Thu Aug 18, 2005 4:34 pm
Posts: 33
Hi. My hibernate won't delete.

I've tried loading an object, then calling the session.delete(object), which doesn't seem to work.

I also made an HQL delete query to delete the object.

Query deleteOldBoardroom = theSession.createQuery("DELETE FROM Boardroom WHERE boardroomId = :bid AND pendingStatus = 0");

deleteOldBoardroom.setInteger("bid", getBoardroomId().intValue());
deleteOldBoardroom.executeUpdate();


There is also an insert inside the same transaction which works fine. This delete doesn't seem to work, and inside the log, I see the SQL (sql is on) output for the INSERT statement, but I see no sql for any delete statement anywhere. So the transaction is going through for some reason...

Any ideas?

Thanks,
Greg


Top
 Profile  
 
 Post subject: details
PostPosted: Thu Aug 25, 2005 4:20 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
>>session.delete(object), which doesn't seem to work.
Could not belive it did not - please more details

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: Deletion of Record
PostPosted: Fri Aug 26, 2005 3:18 am 
Newbie

Joined: Wed Aug 24, 2005 12:07 pm
Posts: 17
Hi Friends,
To delete a particular record you can try this code:

String qry = "delete "+ObjectClassName +" where userName = :userName";
int query = session.createQuery(qry).setString("userName","chirag9")
.executeUpdate();

Thanx and Regards,
Chirag
Software Engineer,
Yash Tech. Inc.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 26, 2005 5:18 am 
Newbie

Joined: Fri Jul 30, 2004 9:02 am
Posts: 9
Location: Ukraine
Seems that problem is with transaction managment, try to start befor and commit transaction after deleting object. Or properly describe transaction handling in hibernate configuration file. Good luck.

_________________
--
Let's do a life easier


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 26, 2005 9:25 am 
Beginner
Beginner

Joined: Thu Aug 18, 2005 4:34 pm
Posts: 33
Here is the code. In my log I see no INSERT's or DELETEs performed.

Code:
Session theSession = BoardroomFinder.getSessionFactory().openSession();
      Transaction tx = theSession.beginTransaction();
      
      if (getPendingStatus().intValue() == Boardroom.NEW)
      {
         setPendingStatus(new Integer(0));
         setLastUpdate(new Date());
         theSession.saveOrUpdate(this);
      }
      else if (getPendingStatus().intValue() == Boardroom.MODIFY)
      {
         Query deleteOldBoardroom = theSession.createQuery("DELETE FROM Boardroom WHERE boardroomId = :bid AND pendingStatus = 0");
         deleteOldBoardroom.setInteger("bid", getBoardroomId().intValue());
         deleteOldBoardroom.executeUpdate();
      }
      else if (getPendingStatus().intValue() == Boardroom.DELETED)
      {
         Query deleteBoardrooms = theSession.createQuery("DELETE FROM Boardroom WHERE boardroomId = :bid");
         deleteBoardrooms.executeUpdate();
      }

      tx.commit();
      theSession.close();


Log file
Code:
[8/26/05 9:16:36:734 EDT] 3e108d4b SessionFactor I org.hibernate.impl.SessionFactoryImpl  building session factory
[8/26/05 9:16:36:750 EDT] 3e108d4b Configurator  W net.sf.ehcache.config.Configurator  No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: wsjar:file:/C:/Program Files/WebSphere/AppServer/installedApps/lithium/BoardroomFinder.ear/boardroom.war/WEB-INF/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
[8/26/05 9:16:37:906 EDT] 3e108d4b SessionFactor I org.hibernate.impl.SessionFactoryObjectFactory  Not binding factory to JNDI, no JNDI name configured
[8/26/05 9:16:37:906 EDT] 3e108d4b SessionFactor I org.hibernate.impl.SessionFactoryImpl  Checking 0 named queries
[8/26/05 9:16:38:297 EDT] 3e108d4b SystemOut     O Hibernate: select capability0_.ID as ID, capability0_.ENGLISHTEXT as ENGLISHT2_1_, capability0_.FRENCHTEXT as FRENCHTEXT1_, capability0_.OFFSET as OFFSET1_, capability0_.ENGLISHDESCRIPTION as ENGLISHD5_1_, capability0_.FRENCHDESCRIPTION as FRENCHDE6_1_ from SBF_CAPABILITY capability0_ order by OFFSET
[8/26/05 9:16:43:015 EDT] 3e108d4b WebGroup      I SRVE0180I: [<null>] [/finder] [Servlet.LOG]: /updates.jsp: init
[8/26/05 9:16:43:031 EDT] 3e108d4b SystemOut     O Hibernate: select boardroom0_.ID as ID, boardroom0_.BOARDROOMID as BOARDROO2_0_, boardroom0_.DEPARTMENTID as DEPARTME3_0_, boardroom0_.PENDINGSTATUS as PENDINGS4_0_, boardroom0_.ENGLISHTITLE as ENGLISHT5_0_, boardroom0_.FRENCHTITLE as FRENCHTI6_0_, boardroom0_.ENGLISHADDRESS as ENGLISHA7_0_, boardroom0_.FRENCHADDRESS as FRENCHAD8_0_, boardroom0_.PROVINCE as PROVINCE0_, boardroom0_.CITY as CITY0_, boardroom0_.MINCAPACITY as MINCAPA11_0_, boardroom0_.MAXCAPACITY as MAXCAPA12_0_, boardroom0_.ENGLISHNOTES as ENGLISH13_0_, boardroom0_.FRENCHNOTES as FRENCHN14_0_, boardroom0_.CAPABILITY as CAPABILITY0_, boardroom0_.LASTUPDATE as LASTUPDATE0_, boardroom0_.UPDATEDBY as UPDATEDBY0_, boardroom0_.UPDATEDNOTES as UPDATED18_0_, boardroom0_.TELEPHONE1 as TELEPHONE19_0_, boardroom0_.TELEPHONE2 as TELEPHONE20_0_, boardroom0_.FAX as FAX0_, boardroom0_.EMAIL as EMAIL0_ from SBF_BOARDROOM boardroom0_ where boardroom0_.PENDINGSTATUS>0
[8/26/05 9:16:45:218 EDT] 3e108d4b WebGroup      I SRVE0180I: [<null>] [/finder] [Servlet.LOG]: /updatesHandler.jsp: init
[8/26/05 9:16:45:234 EDT] 3e108d4b SystemOut     O Hibernate: select boardroom0_.ID as ID, boardroom0_.BOARDROOMID as BOARDROO2_0_, boardroom0_.DEPARTMENTID as DEPARTME3_0_, boardroom0_.PENDINGSTATUS as PENDINGS4_0_, boardroom0_.ENGLISHTITLE as ENGLISHT5_0_, boardroom0_.FRENCHTITLE as FRENCHTI6_0_, boardroom0_.ENGLISHADDRESS as ENGLISHA7_0_, boardroom0_.FRENCHADDRESS as FRENCHAD8_0_, boardroom0_.PROVINCE as PROVINCE0_, boardroom0_.CITY as CITY0_, boardroom0_.MINCAPACITY as MINCAPA11_0_, boardroom0_.MAXCAPACITY as MAXCAPA12_0_, boardroom0_.ENGLISHNOTES as ENGLISH13_0_, boardroom0_.FRENCHNOTES as FRENCHN14_0_, boardroom0_.CAPABILITY as CAPABILITY0_, boardroom0_.LASTUPDATE as LASTUPDATE0_, boardroom0_.UPDATEDBY as UPDATEDBY0_, boardroom0_.UPDATEDNOTES as UPDATED18_0_, boardroom0_.TELEPHONE1 as TELEPHONE19_0_, boardroom0_.TELEPHONE2 as TELEPHONE20_0_, boardroom0_.FAX as FAX0_, boardroom0_.EMAIL as EMAIL0_ from SBF_BOARDROOM boardroom0_ where ID=8
[8/26/05 9:16:45:249 EDT] 7a47cd4e WebGroup      I SRVE0180I: [<null>] [/finder] [Servlet.LOG]: /editBoardroom.jsp: init
[8/26/05 9:16:45:249 EDT] 7a47cd4e SystemOut     O Hibernate: select boardroom0_.ID as ID, boardroom0_.BOARDROOMID as BOARDROO2_0_, boardroom0_.DEPARTMENTID as DEPARTME3_0_, boardroom0_.PENDINGSTATUS as PENDINGS4_0_, boardroom0_.ENGLISHTITLE as ENGLISHT5_0_, boardroom0_.FRENCHTITLE as FRENCHTI6_0_, boardroom0_.ENGLISHADDRESS as ENGLISHA7_0_, boardroom0_.FRENCHADDRESS as FRENCHAD8_0_, boardroom0_.PROVINCE as PROVINCE0_, boardroom0_.CITY as CITY0_, boardroom0_.MINCAPACITY as MINCAPA11_0_, boardroom0_.MAXCAPACITY as MAXCAPA12_0_, boardroom0_.ENGLISHNOTES as ENGLISH13_0_, boardroom0_.FRENCHNOTES as FRENCHN14_0_, boardroom0_.CAPABILITY as CAPABILITY0_, boardroom0_.LASTUPDATE as LASTUPDATE0_, boardroom0_.UPDATEDBY as UPDATEDBY0_, boardroom0_.UPDATEDNOTES as UPDATED18_0_, boardroom0_.TELEPHONE1 as TELEPHONE19_0_, boardroom0_.TELEPHONE2 as TELEPHONE20_0_, boardroom0_.FAX as FAX0_, boardroom0_.EMAIL as EMAIL0_ from SBF_BOARDROOM boardroom0_ where ID=8
[8/26/05 9:16:45:312 EDT] 7a47cd4e SharedPool    I J2CA0086W: Shareable connection MCWrapper id 5f804d5f  Managed connection com.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl@3f70cd5f  State:STATE_TRAN_WRAPPER_INUSE
from resource jdbc/padDS was used within a local transaction containment boundary.
[8/26/05 9:16:45:312 EDT] 7a47cd4e SystemOut     O Hibernate: SELECT capability.ID as ID0_, capability.ENGLISHTEXT as ENGLISHT2_1_0_, capability.FRENCHTEXT as FRENCHTEXT1_0_, capability.OFFSET as OFFSET1_0_, capability.ENGLISHDESCRIPTION as ENGLISHD5_1_0_, capability.FRENCHDESCRIPTION as FRENCHDE6_1_0_ FROM sbf_capability capability ORDER BY strip_html(capability.englishText)
[8/26/05 9:16:50:218 EDT] 7a47cd4e WebGroup      I SRVE0180I: [<null>] [/finder] [Servlet.LOG]: /boardroomHandler.jsp: init
[8/26/05 9:16:50:249 EDT] 7a47cd4e SystemOut     O Hibernate: delete from SBF_BOARDROOM where BOARDROOMID=? and PENDINGSTATUS=0
[8/26/05 9:18:20:461 EDT] 790d0d4d WebGroup      I SRVE0180I: [<null>] [/finder] [Servlet.LOG]: SimpleFileServlet: destroy
[8/26/05 9:18:20:461 EDT] 790d0d4d WebGroup      I SRVE0180I: [<null>] [/finder] [Servlet.LOG]: JSP 1.2 Processor:  destroy
[8/26/05 9:18:20:571 EDT] 790d0d4d WebGroup      I SRVE0180I: [<null>] [/finder] [Servlet.LOG]: JSP 1.2 Processor: init
[8/26/05 9:18:20:758 EDT] 790d0d4d WebGroup      I SRVE0180I: [<null>] [/finder] [Servlet.LOG]: SimpleFileServlet: init
[8/26/05 9:20:37:046 EDT] 3e108d4b WebGroup      I SRVE0180I: [<null>] [/finder] [Servlet.LOG]: /capability.jsp: init


Top
 Profile  
 
 Post subject: I see a delete
PostPosted: Fri Aug 26, 2005 10:59 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Try to remove that if logic and isolate problem, it might be about wrong status,
and by the way I see one delete in the log:
Code:
[8/26/05 9:16:50:249 EDT] 7a47cd4e SystemOut     O Hibernate: delete from SBF_BOARDROOM where BOARDROOMID=? and PENDINGSTATUS=0

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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