-->
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: Some questions on SessionFactory.getCurrentSession() usage
PostPosted: Thu Nov 10, 2005 1:38 am 
Newbie

Joined: Wed Oct 19, 2005 1:14 am
Posts: 7
Location: Chennai
Hi all,

1, Can I keep an instance of Session if I get it using SessionFactory.getCurrentSession().
2, I am unable to make a call to session.toString() if I get session using SessionFactory.getCurrentSession(). It is throwing error
org.hibernate.HibernateException: toString is not valid without active transaction
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:268)


rgds
Anto Paul


Top
 Profile  
 
 Post subject: Re: Some questions on SessionFactory.getCurrentSession() usa
PostPosted: Thu Nov 10, 2005 6:52 am 
Newbie

Joined: Thu Oct 20, 2005 7:48 am
Posts: 19
When u r using same table and database, u have to get the session one time only. then u can use it as u want ... dont spend time to configure it every time.
and tostring will giver errro. because it might not returning any object which can be represented as string..

Hardik.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 12:48 am 
Newbie

Joined: Wed Oct 19, 2005 1:14 am
Posts: 7
Location: Chennai
I don't think the reason for error is that. This is the code fragment I used. I used release RC2.


Session session = sessionFactory.getCurrentSession();
sessionFactory.getCurrentSession().beginTransaction();
logger.info("Printing Session " + session);
sessionFactory.getCurrentSession().save(employee);
sessionFactory.getCurrentSession().getTransaction().commit();
logger.info("Printing Session after commit " + session);

When I checked the source(thank God it is bundled with the download) it is allowing only certain methods to execute if the session don't have an active transaction. This is code from ThreadLocalSessionContext that is throwing error.

if ( !realSession.getTransaction().isActive() ) {
// limit the methods available if no transaction is active
if ( "beginTransaction".equals( method.getName() )
|| "getTransaction".equals( method.getName() )
|| "isTransactionInProgress".equals( method.getName() )
|| "isOpen".equals( method.getName() ) ) {
log.trace( "allowing method [" + method.getName() + "] is non-transacted context" );
}
else {
throw new HibernateException( method.getName() + " is not valid without active transaction" );
}
}


I think the methods toString and equals must be added to the list of allowed methods.


rgds
Anto Paul


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.