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.toString);
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.toString);
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

Environment

Windows XP Home Edition; Java 1.5.0_08 (JDK); MySQL server 5.0; MySQL Connector/J 3.0 or 3.1 (doesn't matter)

Activity

Show:
Christian Bauer
August 30, 2006, 7:59 PM

http://forum.hibernate.org

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

Steve Ebersole
March 21, 2011, 7:05 PM

Bulk closing stale resolved issues

Rejected

Assignee

Unassigned

Reporter

Timothy Heider

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure