-->
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.  [ 4 posts ] 
Author Message
 Post subject: About Hibernate Session
PostPosted: Thu Nov 17, 2005 7:27 pm 
Newbie

Joined: Thu Nov 17, 2005 7:05 pm
Posts: 2
Hi,
I'm a newbie in Hibernate.I'm hoping someone would answer..

In our application we are using Spring services and Hibernate as ORM.Now, the Spring injects a session factory to the DAO everything is great so faar..

The question is :- In my DAO if I access Hibernate Session as
Session session = SessionFactoryUtils.getSession(getSessionFactory(), false);

does this session be in the Transaction as the Spring? Can it see the Transaction Attributes set on it or its a completely or purely Hibernate Session and does not know about Spring..

Just to reiterate the question,If I have a query running under Spring transaction with Spring session (from SessionFactory) and I get the Hibernate Session as shown above and run another query using Hibernate Session will both the queries use the same Transaction and Transaction Attributes or different..

Thanks,
sa


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 8:09 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
i think no, because spring begin and end transaction own (i don't sure for sping; i don't use it more for database access)

for hibernate if you open transaction you use it while don't commit/rollback
see Session#beginTransaction


Top
 Profile  
 
 Post subject: Hibernate Session
PostPosted: Fri Nov 18, 2005 4:24 pm 
Newbie

Joined: Thu Nov 17, 2005 7:05 pm
Posts: 2
Hi,
First of all thank you for responding.
I think I did not explain the question well..

Here is what I want to know:-
I was reading an article which says..

Spring allows you to manage transactions declaratively:-
An Example from the article :-

<bean id="userDAOTarget" class="net.sf.hibernateExamples.UserDAOImpl">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>

<bean id="transactionManager"
class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
</bean>

<bean id="userDAO"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref local="transactionManager"/></property>
<property name="target"><ref local="userDAOTarget"/></property>
<property name="transactionAttributes">
<props>
<prop key="addGroup">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>


Now This is UserDAO.java in which spring gets Hibernate Session behind the scenes and does a save.
[UserDAO.java]
/**
* @param group
*/
public void addGroup(Group group) {
getHibernateTemplate().save(group);


}


Now I'm adding another method here which gets the Hibernate Session but unaware of Spring I guess.. and I'm trying to save does both the saves will be under Spring transaction?

What are DONT's that we need to do to not to go out of Spring control?



[UserDAO.java]
/**
* @param group
*/
public void addGroup(Group group) {
getHibernateTemplate().save(group);

Session session = SessionFactoryUtils.getSession(getSessionFactory(), false);
session.save(anothergroup);

}

Thanks,
sa


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 4:51 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
i don't sure ( i don't know spring enough), but i think that you will work in same transaction

you can debug - and call session.getTransaction() after
getHibernateTemplate().save(group);

and before

session.save(anothergroup);

getTransaction() exits in last hibernate (3.1 only i think)


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