 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
bobbymartin2@gmail.com Guest
|
Posted: Tue Dec 07, 2004 3:48 am Post subject: New mysql version enforces hibernate semantics |
|
|
I had a problem and solved it - I'm just posting here for posterity.
The symptoms:
Everything worked great in my hibernate/mysql project, then I upgraded
mysql to version 4.1.7. Insert and update just stopped working - the
code all looks fine, but the commit never takes place. I was typically
using code like so:
Session session = sessionFactory.openSession();
session.save(someObject);
session.close();
with of course some try/catch/finally code integrated. The issue is
that I had apparently just ignored the instructions on insert and
update in hibernate when I initially coded it, which clearly say to use
something more like this:
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.save(someObject);
tx.commit();
session.close();
with of course some try/catch/finally involved. This worked OK with
the previous version of mysql but not at all with the 4.1.7. The final
result should look something like:
Transaction tx = null;
Session session = null;
try {
session = sessionFactory.openSession();
tx = session.beginTransaction();
session.save(someObject);
tx.commit();
}
catch(Exception e) {
if( tx != null ) tx.rollback();
}
finally {
if( session != null ) session.close();
}
The above code fixes the problem.
This problem is particularly frustrating because everything worked
before, and everything still appears to work in java, your data just
doesn't make it into the db.
Hope that helps someone
|
|
| Back to top |
|
 |
Mark Matthews Guest
|
Posted: Tue Dec 07, 2004 6:40 pm Post subject: Re: New mysql version enforces hibernate semantics |
|
|
[email]bobbymartin2 (AT) gmail (DOT) com[/email] wrote:
| Quote: | I had a problem and solved it - I'm just posting here for posterity.
The symptoms:
Everything worked great in my hibernate/mysql project, then I upgraded
mysql to version 4.1.7. Insert and update just stopped working - the
code all looks fine, but the commit never takes place. I was typically
using code like so:
Session session = sessionFactory.openSession();
session.save(someObject);
session.close();
with of course some try/catch/finally code integrated. The issue is
that I had apparently just ignored the instructions on insert and
update in hibernate when I initially coded it, which clearly say to use
something more like this:
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.save(someObject);
tx.commit();
session.close();
with of course some try/catch/finally involved. This worked OK with
the previous version of mysql but not at all with the 4.1.7. The final
result should look something like:
Transaction tx = null;
Session session = null;
try {
session = sessionFactory.openSession();
tx = session.beginTransaction();
session.save(someObject);
tx.commit();
}
catch(Exception e) {
if( tx != null ) tx.rollback();
}
finally {
if( session != null ) session.close();
}
The above code fixes the problem.
This problem is particularly frustrating because everything worked
before, and everything still appears to work in java, your data just
doesn't make it into the db.
Hope that helps someone
|
Hmm,
That's interesting, as I don't know of any changes to MySQL server or
the JDBC driver that would cause this behavior...
Any chance you could send me the SQL that hibernate is sending to the
server in both cases? (i.e. either by using the hibernate properties to
log the generated sql, or the 'general' log of MySQL)?
-Mark
|
|
| Back to top |
|
 |
|
|
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 You cannot vote in polls in this forum
|
|