-->
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: session.find after session.Delete problem
PostPosted: Sun Jan 25, 2004 5:31 am 
Beginner
Beginner

Joined: Thu Dec 25, 2003 8:08 am
Posts: 26
I have the following code:

Code:
   Session session = null;
   try {
     // get factory and open session
     SessionFactory factory = HibernateConfiguration.getInstance().getFactory();
     session = factory.openSession();
     // create rule list
     Transaction t = session.beginTransaction();
     RuleListBO ruleList = new RuleListBO();
     session.save(ruleList);
     t.commit();
     session.clear();
     // delete rule list
     t = session.beginTransaction();
     Long id = new Long(ruleList.getId().getInternalID());
     ruleList = (RuleListBO)session.get(RuleListBO.class, id);
     session.delete(ruleList);
     List list = session.find(
         "select from RuleListBO as rulelist where rulelist.pyramidName = ?",
         "Nwind", Hibernate.STRING);
     t.rollback();
   }
   catch (Exception e) {
     e.printStackTrace();
   }
   finally {
     try {
       if (session != null) {
         session.close();
       }
     }
     catch (Exception e) {
       e.printStackTrace();
     }
   }


What I see is that the object gets deleted the minute the session.find method is executed. Not even the rollback reverts the deletion. I'm using mySQL 4.0.16 on windows, JDBC driver version 3.0.9

Am I missing something?
Eyal


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 25, 2004 8:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
First: You should not reuse a session over multiple transactions. Second: Are you sure you are using mySql tables supporting transactions (innodb)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 25, 2004 8:54 am 
Beginner
Beginner

Joined: Thu Dec 25, 2003 8:08 am
Posts: 26
AFAIK, I can use have a session with multiple transactions but I can't share the session between multiple threads.
Nevertheless, the same problem exists when using a single transaction.

How do I check if my DB supports transactions (what is the innodb?).


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 25, 2004 9:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
The table type of your mysql tables must be InnoDB and not MyISAM. You should not reuse the session with multiple transactions.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 25, 2004 9:19 am 
Beginner
Beginner

Joined: Thu Dec 25, 2003 8:08 am
Posts: 26
OK, I understand but I still got the problem.
The tables type are MyISAM, but they were created by Hibernate. Is it some sort of mySQL configuration I should change?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 25, 2004 9:55 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You can re-use the same Session with multiple database transactions. Thats the whole point of the Session ;)

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 25, 2004 9:55 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Use the search function next time:

http://www.hibernate.org/119.html#A8

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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.