I'm new to Spring, but i've read a lot of documentation(even searched this forum for this topic) , but still can't figure this one out. need help from anyone with experience with @Transactional using <tx:annotation-driven>
I have this:
...
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven/>
...
"sessionFactory" is correctly defined.
Then my service class (Which uses Hibernate 3.1) has this:
...
@Transactional(propagation=Propagation.REQUIRES_NE W, readOnly=true)
public User getUserByUsername(String username) {
return ((User) getSession()
.createQuery("from User u where u.username like :un")
.setString("un", username)
.setMaxResults(1)
.uniqueResult());
}
...
then this is from the stack trace:
...
09:51:11,491 ERROR AutoHandler:30 - createQuery is not valid without active transaction
org.hibernate.HibernateException: createQuery is not valid without active transaction
at org.hibernate.context.ThreadLocalSessionContext$Tr ansactionProtectionWrapper.invoke(ThreadLocalSessi onContext.java:297)
at $Proxy39.createQuery(Unknown Source)
at net.ehosp.model.daoImpl.UserDAOHibernate.getUserBy Username(UserDAOHibernate.java:61)
at net.ehosp.controller.LoginActionBean.login(LoginAc tionBean.java:136)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
Any ideas? is this a problem with hibernate?


Reply With Quote