-->
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.  [ 2 posts ] 
Author Message
 Post subject: SessionFactory.getCurrentSession()... does this create
PostPosted: Thu Mar 16, 2006 7:13 pm 
Newbie

Joined: Wed Mar 15, 2006 3:20 pm
Posts: 7
I'm executing a command on every request of a process, and this process might or might NOT access any hibernate functions. At the very end of this process i'm running...
Code:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.getTransaction().commit();

Does the getCurrentSession() and the getTransaction() in the statements actualy create new objects if none exist? As I said above, the process might or might NOT use any Hibernate functions, and if it doesn't then I dont want to create anything new. If it does of course, then i want to close everything.

I hope I'm being clear!

Thanks,
Eurig


Top
 Profile  
 
 Post subject: 2c
PostPosted: Fri Mar 17, 2006 7:40 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
It does create new session. However Hibernate session is very lightweight object, so I would suggest you not to worry about it.

If you still do, then wrap your code into some lazily instantiated ThreadLocal and on exit check if it has been initialized at all and then call commit.

If( thl.getSession() != null) {
thl.getSession().getTransaction().commit();
}

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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