Rejected
Details
Assignee
UnassignedUnassignedReporter
Timothy HeiderTimothy HeiderComponents
Affects versions
Priority
Major
Details
Details
Assignee
Unassigned
UnassignedReporter
Timothy Heider
Timothy HeiderComponents
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
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