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.  [ 5 posts ] 
Author Message
 Post subject: Cannot delete rows from InnoDB table, but CAN from MyISAM
PostPosted: Tue Jun 03, 2008 7:35 pm 
Newbie

Joined: Wed Jan 17, 2007 9:20 pm
Posts: 7
Hi,

Weird problem I haven't seen before: I can insert and delete rows without problem when the MySQL table is MyISAM. However, when I change the storage engine to InnoDB, Hibernate can only insert, but not delete.

The only way I've found to programatically delete the rows is to use straight SQL directly on the Connection.

I've replicated this on two MySQL databases (5.0.45 and 5.0.27). I've used two different drivers (5.0.4 and 5.1.6).

I'm using Hibernate 3.2.2.ga.

The table is dead simple with no relationships and one autogenerated key.

Any ideas?

Michael


Top
 Profile  
 
 Post subject: New Info
PostPosted: Wed Jun 04, 2008 11:46 am 
Newbie

Joined: Wed Jan 17, 2007 9:20 pm
Posts: 7
I wrote a very simple main method program:

Player player2 = new Player();
player2.setId(2);
player2.setName("aName");

Transaction t = HibernateUtil.beginTransaction();
HibernateUtil.delete(player2);
t.commit();
HibernateUtil.flush();

The database has a Player table with one row with primary key = 2. This program cannot delete the row when the table is InnoDB.


Top
 Profile  
 
 Post subject: More information
PostPosted: Wed Jun 04, 2008 12:33 pm 
Newbie

Joined: Wed Jan 17, 2007 9:20 pm
Posts: 7
I wrote another test that tries to modify a record inside a transcation:

player2.setName("newName");
Transaction t = HibernateUtil.getSession().beginTransaction();
HibernateUtil.saveOrUpdate(player2);
t.commit();
HibernateUtil.flush();
HibernateUtil.closeSession();

The fourth line throws a TransactionException: Transaction not successfully started.

So it appears there's a problem with starting the transaction, and this is probably the root problem.


Top
 Profile  
 
 Post subject: SOLUTION
PostPosted: Wed Jun 04, 2008 2:03 pm 
Newbie

Joined: Wed Jan 17, 2007 9:20 pm
Posts: 7
I figured it out. The problem goes away when I comment out the the line in the hibernate.properties file that sets the c3p0.max_size.

Leaving all else equal, a hibernate.properties file with

hibernate.c3p0.max_size 20 will cause my tests to fail. On the other hand, when that line is commented out, all the tests pass.

Very strange. Anybody on this forum know why?


****

To future Googlers with the same problem: award me some points if this solution helped you!


Top
 Profile  
 
 Post subject: Real Solution
PostPosted: Wed Jun 04, 2008 2:51 pm 
Newbie

Joined: Wed Jan 17, 2007 9:20 pm
Posts: 7
Actually after further testing, I have discovered the real problem: I needed to flush() then commit() rather than commit() then flush().


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