Announcement Announcement Module
Collapse
No announcement yet.
Spring Transactions and Hibernate Criteria Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Transactions and Hibernate Criteria

    Hi All,
    I'm a Hibernate newbie and am having a problem using the Criteria API with Spring Transactions.

    I'm using Spring 2.5 and Hibernate 3.2.4.
    Transactions appear to be working fine for normal JTA operations, but when I come to use the Hibernate specific stuff, like Criteria, everything falls over. Here's the scenario...

    I have a DAO which has the @Transactional annotation at the top of the class. In my DAO I have a method like this...

    Code:
    public List<T> getAllByExample(T example) {
    	Session currentSession = template.getSessionFactory().getCurrentSession();
    	Criteria criteria = currentSession.createCriteria(example.getClass());
    	Example hibExample = Example.create(example);
    	return criteria.add(hibExample).list();
    }
    The first line of this method complains that the current session is not configured...
    Code:
    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.HibernateException: No CurrentSessionContext configured!
    My persistance.xml looks like this...
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    	version="1.0">
    
    	<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
     		<provider>org.hibernate.ejb.HibernatePersistence</provider> 
    		<properties>
    			<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
    			<property name="hibernate.ejb.autodetection" value="class" />
    			<property name="hibernate.default_schema" value="dbo"/> 
    		</properties>
    	</persistence-unit>
    </persistence>
    I tried setting the current session by adding the line...
    Code:
    <property name="hibernate.current_session_context_class" value="jta"/>
    However, it now complains...
    Code:
    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.HibernateException: No TransactionManagerLookup specified
    I've tried loads of other configurations, but to no avail
    Does anyone have any ideas?
    Thanks,
    Owen

  • #2
    Try this

    I see this is an old post so I suppose you have this working by now. If not, try this:

    Code:
    	<!--Support for Annotated Transactions - Short and sweet!-->
    	<tx:annotation-driven transaction-manager="transactionManager"/>
    	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory" ref="sessionFactory"/>
    	</bean>

    Comment


    • #3
      This might also be helpful

      I had the hibernate.current_session_context_class=thread but I needed:

      Code:
      <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate3.SpringSessionContext</prop>

      Comment

      Working...
      X