-->
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.  [ 7 posts ] 
Author Message
 Post subject: Hibernate not deleting, help
PostPosted: Thu May 19, 2005 10:20 am 
Newbie

Joined: Thu May 19, 2005 7:09 am
Posts: 4
Hi there,

First things first:

Hibernate version:2.1.6 (with JBoss 4.0.1 sp1)
Mapping documents:Simple documents, nothing special here
Code between sessionFactory.openSession() and session.close():I'm using HibernateContext.getSession(...)
Full stack trace of any exception that occurs:No exception, that's part of my problem
Name and version of the database you are using:Oracle 9i
The generated SQL (show_sql=true): Not applicable
Debug level Hibernate log excerpt: Later...

I use Hibernate in various stateless session bean and in a MDB. My database and mappings are simple, nothing special.
The problem is that when I try to delete the content of a table, Hibernate says he does it, but in the bd nothing happens.

I use
Code:
org.jboss.hibernate.session.HibernateContext.getSession("java:/hibernateDim/SessionFactory");

to obtain the hibernate session, and then
Code:
      Transaction tx = null;
      try {         
         tx = hibernateSession.beginTransaction();
         logger.info("Deleting table CapacidadRequeridaBean");
         hibernateSession.delete("from CapacidadRequeridaBean");
         logger.info("Deleting table RechazoBean");
         hibernateSession.delete("from RechazoBean");
         hibernateSession.flush();
         tx.commit();
      } catch (Exception e) {
         logger.error("Cannot clean tables",e);
         if (tx != null)
            tx.rollback();
      } finally {
                      // Do nothing there. Was using closeSession() when using sessionFactory
      }


to delete the tables.

When I look at the detailed debug output of hibernate, I don't see anything odd. Hibernate fetches entities to delete, prepares statements, and then does the flushing when it's called. Then it prepares all the necessary JDBC batches and executes them:

Quote:
2005-05-19 12:07:24,094 DEBUG [net.sf.hibernate.impl.BatcherImpl] Executing batch size: 15
2005-05-19 12:07:24,100 DEBUG [net.sf.hibernate.impl.BatcherImpl] success of batch update unknown: 0
2005-05-19 12:07:24,100 DEBUG [net.sf.hibernate.impl.BatcherImpl] success of batch update unknown: 1
2005-05-19 12:07:24,100 DEBUG [net.sf.hibernate.impl.BatcherImpl] success of batch update unknown: 2
2005-05-19 12:07:24,100 DEBUG [net.sf.hibernate.impl.BatcherImpl] success of batch update unknown: 3


Finally it executes :

Quote:
2005-05-19 12:07:24,140 DEBUG [net.sf.hibernate.impl.SessionImpl] post flush
2005-05-19 12:07:24,142 DEBUG [net.sf.hibernate.transaction.JTATransaction] commit


In the database we don't see any change. Later, the MDB tries to saveOrUpdate an object in one of the deleted tables and it seems to produce a deadlock... It's very strange, we don't know what can be happening. Has anyone experienced something similar ??

We need some help here, the faqs and examples didn't help in this case.

Regards,

Gerald.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 19, 2005 11:17 am 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
I have had similar problems. Here is what I have learned:

If you are executing hibernated in a J2EE container, you need to work with JTATransactions and, in your case, with your JBoss Transaction Manager. not with the default HibernateTransactionManager.

I've had the same problem using the default HibernateTransactionManager while deployed in Weblogic. Nothing was persisted in the DB and tables got locked up. Maybe you are running in the same issue

Something else that I have learned: If you work in a multi-tier environment, it is better to initialize an association collections before working with it. using Hibernate.initialize(object.getAssociation(); Otherwise, things might not be persisted (because the association proxy might not be initialized and will not see the changes you make to a collection - association).


buena suerte :P

Vincent.

_________________
Vincent Giguère
J2EE Developer


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 5:12 am 
Newbie

Joined: Thu May 19, 2005 7:09 am
Posts: 4
Hi,

Thanks for the reply and the advice. It seems that finally there's no "deadlock" but more that the delete operation was not committed and it blocks further operations on the same table. I've checked that the transaction manager used is the one from JBoss.

I don't understand well how work the transactions in jboss (or maybe in j2ee); tell me if I'm wrong: there's one transaction for every EJB invocation ? Maybe it's our problem. The whole process is included in one session bean method, and if the transaction does not commit until the end of the method, the intermediate operations like table deleting cannot commit ?

Trying to access the UserTransaction object results in an exception saying that I cannot obtain the transaction in a Container Managed Transaction bean... Maybe I could manage the transactions myself ?

Regards,

Gerald.

(a ver si hay suerte ;))


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 5:14 am 
Newbie

Joined: Thu May 19, 2005 7:09 am
Posts: 4
Ups, I forgot saying that we managed to delete the table and commit the changes using a quite... dirty trick: we created a procedure in Oracle that deletes the table and commit the changes... that is, outside the scope of hibernate and jboss...


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 9:19 am 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
You say that you want to delete a table, but my understanding is that you actually want to delete all the data from a table, and not the table itself. Correct me if I'm wrong (because the queries you issue will not delete the table itself).

Post your hibernate configuration file to see if there is something missing. Or try to search on the web for a typical jboss hibernate.cfg.xml.

I am thinking that you may have a problem with nested transactions or something of that kind.

Try to extract the code of your EJBean and put it in a standard java class and see how it behaves. If it works fine, then you'll know that it is cause by your bean's transaction management.

If you can't do that, you could modify your bean deployment descriptor and make sure that no transactions are required for the methods of your bean.

Good Luck,
Vincent

_________________
Vincent Giguère
J2EE Developer


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 9:22 am 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
I forgot:

You do not need to issue the following command:
hibernateSession.flush()
This will be done for you when you commit the transaction.

_________________
Vincent Giguère
J2EE Developer


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 27, 2005 3:34 am 
Newbie

Joined: Thu May 19, 2005 7:09 am
Posts: 4
Actually I only need to delete the data from the table, not the table itself, you're right.
I think you're right too about transactions. The fact is that if I run the delete code as a bean method, it works perfectly; the only difference with the actual code is that the container commits the transaction that begins and ends with the bean's method. In the actual code, we run a single bean method that does a lot of things (including the delete) but it would only commit at the end, but we cannot reach the end of the method because of some sort of lock between the delete on a table and later an update on the same table.
I think I should use BMT instead of CMT and define some transactions myself. I'll post the result when I can test it.

Regards,

Gerald.


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