problem with MySQL 5.0 in a standalone application; unable to insert records in a certain case

Description

Hello,

I have found a workaround for this, but I wanted to report my experience.

I am starting out with Hibernate and have spent the past few days building my "hello world" ap.

I finally got SchemaExport working and my configuration set up. My database is all set up, etc.

When I do this, it works:

public static void main(String[] args) {
Configuration cfg = new Configuration();
SessionFactory factory = cfg.configure("primeschedule/hibernate/hibernate.cfg.xml").buildSessionFactory();
for(int i=0;i < 5;i++) {
Session session = factory.openSession();
session.beginTransaction();
Practice p = new Practice();
p.setName("tim-" + Integer.toStringInfo);
session.save(p);
session.getTransaction().commit();
session.close();
}
factory.close();
}

but when I do this it does not:

public static void main(String[] args) {
Configuration cfg = new Configuration();
SessionFactory factory = cfg.configure("primeschedule/hibernate/hibernate.cfg.xml").buildSessionFactory();
for(int i=0;i < 5;i++) {
Session session = factory.openSession();
session.beginTransaction();
Practice p = new Practice();
p.setName("tim-" + Integer.toStringInfo);
session.save(p);
session.flush();
session.close();
}
factory.close();
}

If I run the second test case in JDB it would actually output junk to the screen and crash! When running test case 2 in the standard java interpreter it outputs the INSERT statement, but the records do not post to the database. Weird.

My workaround is to not use FLUSH but instead use getTransaction().commit(). The book "Hibernate Quickly" suggests using the flush command at the end of the session.

Thanks for your attention,

Tim

Attachments

3
  • 30 Aug 2006, 07:45 PM
  • 30 Aug 2006, 07:45 PM
  • 30 Aug 2006, 07:45 PM

Activity

Steve EbersoleMarch 21, 2011 at 7:05 PM

Bulk closing stale resolved issues

Christian BauerAugust 30, 2006 at 7:59 PM

http://forum.hibernate.org

This book is full of issues, just use the reference documentation tutorial.

Rejected

Details

Assignee

Reporter

Components

Affects versions

Priority

Created August 30, 2006 at 7:45 PM
Updated March 21, 2011 at 7:05 PM
Resolved August 30, 2006 at 7:59 PM

Flag notifications