-->
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.  [ 3 posts ] 
Author Message
 Post subject: SessionFactory.getCurrentSession() with DB2
PostPosted: Sat May 01, 2010 4:30 pm 
Beginner
Beginner

Joined: Mon Aug 22, 2005 9:57 pm
Posts: 27
I encounter a problem with DB2

my DB2 is old, i am using JDBC-ODBC driver , setting is like below
<property name="connection.driver_class">COM.ibm.db2.jdbc.app.DB2Driver</property>
<property name="connection.url">jdbc:db2:XXXXX</property>
<property name="connection.username">XXXX</property>
<property name="connection.password">XXXX</property>
<property name="show_sql">true</property>
<property name="default_schema">XXXX</property>
<property name="dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="current_session_context_class">thread</property>

If i use SessionFactory.getCurrentSession(), then when i use hibernate session to do any operation within transaction.
I will get excpetion said , transaction is not active.

but when i use SessionFactory.openSession() everything works fine.

Anyone knows the reason?

Rgds


Top
 Profile  
 
 Post subject: Re: SessionFactory.getCurrentSession() with DB2
PostPosted: Mon May 03, 2010 9:20 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
According hibernate docu you must call

Code:
sf.getCurrentSession().beginTransaction();


before you begin with transactional work (listing 11.2 in book "java persistence with hibernate").

Quote:
but when i use SessionFactory.openSession() everything works fine.


can it be that there you did just some query, so hibernate did the queries with non-transactional read only access ?


Top
 Profile  
 
 Post subject: Re: SessionFactory.getCurrentSession() with DB2
PostPosted: Tue May 04, 2010 2:20 am 
Beginner
Beginner

Joined: Mon Aug 22, 2005 9:57 pm
Posts: 27
Below is my code, i thought it is also correct

HibernateUtil.getSessionFactory().getCurrentSession()
.beginTransaction();
Criteria query = (Criteria) HibernateUtil.getSessionFactory().getCurrentSession().createCriteria(
Finaceauthority.class);
Collection<Finaceauthority> fas = query.list();
for (Finaceauthority fa : fas) {
logger.info(fa);
}
HibernateUtil.getSessionFactory().getCurrentSession()
.getTransaction().commit();

Then i got exception
org.hibernate.HibernateException: createCriteria is not valid without active transaction


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.