[hibernate-issues] [Hibernate-JIRA] Created: (HHH-2040) problem with MySQL 5.0 in a standalone application; unable to insert records in a certain case

Timothy Heider (JIRA) noreply at atlassian.com
Wed Aug 30 13:45:24 EDT 2006


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

         Key: HHH-2040
         URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2040
     Project: Hibernate3
        Type: Bug

  Components: core  
    Versions: 3.1.2    
 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)
    Reporter: Timothy Heider
 Attachments: Practice.hbm.xml, hibernate-configuration-3.0.dtd, hibernate-mapping-3.0.dtd

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(i));
            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(i));
            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

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list