-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Sample code not working
PostPosted: Tue Jan 11, 2005 8:42 am 
Beginner
Beginner

Joined: Fri Jun 11, 2004 3:42 am
Posts: 22
Any idea why this code is not working for me? Everything seems to be fine. When I include this within transaction, it seems to work!!!

AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.InterbaseDialect");
cfg.setProperty("hibernate.connection.url", "jdbc:firebirdsql:localhost:D:\\FireBirdDB\\mydb.gdb");
cfg.setProperty("hibernate.connection.username", "sysdba");
cfg.setProperty("hibernate.connection.password", "masterkey");
cfg.setProperty("hibernate.connection.driver_class", "org.firebirdsql.jdbc.FBDriver");
cfg.setProperty("hibernate.c3p0.min_size", "5");
cfg.setProperty("hibernate.c3p0.max_size", "20");
cfg.setProperty("hibernate.c3p0.timeout", "1800");
cfg.setProperty("hibernate.c3p0.max_statements", "50");
cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
cfg.setProperty("hibernate.show_sql", "true");
cfg.addAnnotatedClass(Company.class);
SessionFactory sf = cfg.buildSessionFactory();

Session s = sf.openSession();
try {
Company TC = new Company();
TC.setName("aa");
s.save(TC);

Company TC1 = new Company();
TC1.setName("bb");
s.save(TC1);
} catch (Exception e) {
throw e;
} finally {
s.flush();

}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 11, 2005 8:46 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
What?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 11, 2005 8:53 am 
Beginner
Beginner

Joined: Fri Jun 11, 2004 3:42 am
Posts: 22
Im sorry, i did not understand your question. You did not understand what ny question was OR was it something else?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 11, 2005 8:58 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I wonder why you don't fill out the form in the textarea.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 11, 2005 9:01 am 
Beginner
Beginner

Joined: Fri Jun 11, 2004 3:42 am
Posts: 22
I am sorry. I think you ment that you wanted the code to be pasted in a more readable form. I am learning to use the tool bar. Repasting the code again.

Code:
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.InterbaseDialect");
cfg.setProperty("hibernate.connection.url", "jdbc:firebirdsql:localhost:D:\\FireBirdDB\\mydb.gdb");
cfg.setProperty("hibernate.connection.username", "sysdba");
cfg.setProperty("hibernate.connection.password", "masterkey");
cfg.setProperty("hibernate.connection.driver_class", "org.firebirdsql.jdbc.FBDriver");
cfg.setProperty("hibernate.c3p0.min_size", "5");
cfg.setProperty("hibernate.c3p0.max_size", "20");
cfg.setProperty("hibernate.c3p0.timeout", "1800");
cfg.setProperty("hibernate.c3p0.max_statements", "50");
cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
cfg.setProperty("hibernate.show_sql", "true");
cfg.addAnnotatedClass(Company.class);
SessionFactory sf = cfg.buildSessionFactory();

Session s = sf.openSession();
try {
   Company TC = new Company();
   TC.setName("aa");
   s.save(TC);

   Company TC1 = new Company();
   TC1.setName("bb");
   s.save(TC1);
} catch (Exception e) {
   throw e;
} finally {
   s.flush();

}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 11, 2005 9:08 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Your question is confusing. I assume that what you are saying is that the code works when embedded within a transaction but doesn't when no transaction demarcation is declared. This comes as no surprise to us.

From the hibernate reference manual:
Quote:
Ending a session involves four distinct phases:
• flush the session
• commit the transaction
• close the session
• handle exceptions


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 11, 2005 9:27 am 
Beginner
Beginner

Joined: Fri Jun 11, 2004 3:42 am
Posts: 22
Sorry, I missed s.close() AFTER s.flush();. But eitherways here I flush it and then close it, which should automatically commit (even if I am not using Tx). Should this suffice?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 11, 2005 10:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
No, because nowhere are you managing the state of the transaction. Sometimes I think auto-commit has corrupted java developers. In SQL you cannot just perform a DML operation and expect it to "stick" without a transaction.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


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

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.