You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Richard Slide <ri...@gmail.com> on 2010/05/08 11:12:02 UTC
org.hibernate.HibernateException: createCriteria is not valid without
active transaction
Hello all,
i try to do a simple web application with the classic layout
Wicket->Spring->Hibernate
When i try to make a simple request i receive the following error.
WicketMessage: Error attaching this container for rendering: [Page class =
ch.myexample.ListContacts, id = 0, version = 0]
Root cause:
org.hibernate.HibernateException: createCriteria is not valid without active
transaction
In IMHO all file conf seams to be correct correct... bat i don't undestand
hibenate dosen't find the correct session.
At UI level i load the data with LoadableDetachableModel
IModel contactsModel = new LoadableDetachableModel() {
protected Object load() {
return
WicketApplication.get().getContactService().findAllContacts();
}
};
--applicationContext from here --
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>${jdbc.driver}</value>
</property>
<property name="url">
<value>${jdbc.url}</value>
</property>
<property name="username">
<value>${jdbc.username}</value>
</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
</bean>
<!-- hibernate session factory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.connection.pool_size">5</prop>
<prop
key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.show_sql">true</prop>
<prop
key="hibernate.cglib.use_reflection_optimizer">true</prop>
<prop
key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop
key="hibernate.hibernate.cache.use_query_cache">true</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>
ch.myexample.domain.Contact
</value>
</list>
</property>
</bean>
<!-- setup transaction manager -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<tx:annotation-driven />
<bean id="ContactDao" class="ch.myexample.dao.impl.ContactDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="LocalServiceService"
class="ch.myexample.services.LocalServiceImpl">
<property name="contactDao" ref="ContactDao" />
</bean>
<bean id="wicketApplication" class="ch.myexample.WicketApplication">
</bean>
</beans>
--
--applicationContext to here --
and web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value> classpath:applicationContext.xml</param-value>
</context-param>
<filter>
<filter-name>wicket.WebProject</filter-name>
<filter-class>org.apache.wicket.protocol.http.WicketFilter
</filter-class>
<init-param>
<param-name>applicationFactoryClassName
</param-name>
<param-value>
org.apache.wicket.spring.SpringWebApplicationFactory
</param-value>
</init-param>
<init-param>
<param-name>applicationBean</param-name>
<param-value> wicketApplication</param-value>
</init-param>
</filter>
<filter>
<filter-name>opensessioninview</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>opensessioninview</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>wicket.WebProject</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>
Could you tell me where is my mistake please
Cheers
--Richard
Re: org.hibernate.HibernateException: createCriteria is not valid
without active transaction
Posted by James Carman <ja...@carmanconsulting.com>.
By the way, you might want to check out domdrides. It has all this
implemented and tested for you
On May 8, 2010 8:41 AM, "Richard Slide" <ri...@gmail.com> wrote:
I did it.....
On Sat, May 8, 2010 at 2:00 PM, James Carman
<jc...@carmanconsulting.com>wrote:
> Put it on the impl class.
>
> On Sat, May 8, 2010 at 7:43 AM, Richard Slide <richard.slide@gmail....
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: org.hibernate.HibernateException: createCriteria is not valid
without active transaction
Posted by Richard Slide <ri...@gmail.com>.
I did it.....
On Sat, May 8, 2010 at 2:00 PM, James Carman
<jc...@carmanconsulting.com>wrote:
> Put it on the impl class.
>
> On Sat, May 8, 2010 at 7:43 AM, Richard Slide <ri...@gmail.com>
> wrote:
> > Yes i did it...
> > this is DAO and impl
> >
> >
> >
> >
> > public interface Dao<T extends DomainObject> {
> >
> > @Transactional
> > void delete(T o);
> >
> > T load(long id);
> >
> > @Transactional
> > void save(T o);
> >
> > @Transactional
> > List<T> findAll();
> >
> > int countAll();
> > }
> >
> > and the implemetation is
> >
> > public abstract class AbstractHibernateDaoImpl<T extends DomainObject>
> > implements Dao<T> {
> >
> > private Class<T> domainClass;
> >
> > private SessionFactory sf;
> >
> > public AbstractHibernateDaoImpl(Class<T> domainClass) {
> > this.domainClass = domainClass;
> > }
> >
> > public SessionFactory getSessionFactory() {
> > return sf;
> > }
> >
> > public void setSessionFactory(SessionFactory sf) {
> > this.sf = sf;
> > }
> >
> > public void delete(T object) {
> > getSession().delete(object);
> > }
> >
> > @SuppressWarnings("unchecked")
> > public T load(long id) {
> > return (T) getSession().get(domainClass, id);
> > }
> >
> > public void save(T object) {
> > getSession().saveOrUpdate(object);
> > }
> >
> > @SuppressWarnings("unchecked")
> > public List<T> findAll() {
> > Criteria criteria = getSession().createCriteria(domainClass);
> > return (List<T>) criteria.list();
> > }
> >
> > public int countAll() {
> > Criteria criteria = getSession().createCriteria(domainClass);
> > criteria.setProjection(Projections.rowCount());
> > return (Integer) criteria.uniqueResult();
> > }
> >
> > public Session getSession() {
> > // presumes a current session, which we have through the
> > // OpenSessionInViewFilter; doesn't work without that
> > return sf.getCurrentSession();
> > }
> > }
> >
> >
> >
> >
> > On Sat, May 8, 2010 at 12:05 PM, Karolina Rusin <iluu.lists@gmail.com
> >wrote:
> >
> >> Hello Richard,
> >>
> >> Maybe you need to use @Transactional above your dao method?
> >> Hope this helps.
> >>
> >> Best regards,
> >> Karolina Rusin
> >>
> >>
> >> 2010/5/8 Richard Slide <ri...@gmail.com>
> >>
> >> > Hello all,
> >> > i try to do a simple web application with the classic layout
> >> > Wicket->Spring->Hibernate
> >> >
> >> > When i try to make a simple request i receive the following error.
> >> >
> >> > WicketMessage: Error attaching this container for rendering: [Page
> class
> >> =
> >> > ch.myexample.ListContacts, id = 0, version = 0]
> >> > Root cause:
> >> > org.hibernate.HibernateException: createCriteria is not valid without
> >> > active
> >> > transaction
> >> >
> >> > In IMHO all file conf seams to be correct correct... bat i don't
> >> undestand
> >> > hibenate dosen't find the correct session.
> >> >
> >> > At UI level i load the data with LoadableDetachableModel
> >> >
> >> > IModel contactsModel = new LoadableDetachableModel() {
> >> > protected Object load() {
> >> > return
> >> > WicketApplication.get().getContactService().findAllContacts();
> >> > }
> >> > };
> >> >
> >> > --applicationContext from here --
> >> >
> >> > <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
> >> > <property name="driverClassName">
> >> > <value>${jdbc.driver}</value>
> >> > </property>
> >> > <property name="url">
> >> > <value>${jdbc.url}</value>
> >> > </property>
> >> > <property name="username">
> >> > <value>${jdbc.username}</value>
> >> > </property>
> >> > <property name="password">
> >> > <value>${jdbc.password}</value>
> >> > </property>
> >> > </bean>
> >> >
> >> > <!-- hibernate session factory -->
> >> > <bean id="sessionFactory"
> >> >
> >> >
> >> >
> >>
> class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
> >> > <property name="dataSource" ref="dataSource" />
> >> > <property name="hibernateProperties">
> >> > <props>
> >> > <prop
> key="hibernate.dialect">${hibernate.dialect}</prop>
> >> > <prop key="hibernate.connection.pool_size">5</prop>
> >> > <prop
> >> > key="hibernate.current_session_context_class">thread</prop>
> >> > <prop key="hibernate.show_sql">true</prop>
> >> > <prop
> >> > key="hibernate.cglib.use_reflection_optimizer">true</prop>
> >> > <prop
> >> >
> >> >
> >>
> key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
> >> > <prop
> >> > key="hibernate.hibernate.cache.use_query_cache">true</prop>
> >> > </props>
> >> > </property>
> >> > <property name="annotatedClasses">
> >> > <list>
> >> > <value>
> >> > ch.myexample.domain.Contact
> >> > </value>
> >> > </list>
> >> > </property>
> >> > </bean>
> >> >
> >> > <!-- setup transaction manager -->
> >> > <bean id="transactionManager"
> >> >
> >> >
> class="org.springframework.orm.hibernate3.HibernateTransactionManager">
> >> > <property name="sessionFactory">
> >> > <ref bean="sessionFactory" />
> >> > </property>
> >> > </bean>
> >> > <tx:annotation-driven />
> >> > <bean id="ContactDao" class="ch.myexample.dao.impl.ContactDaoImpl">
> >> > <property name="sessionFactory" ref="sessionFactory" />
> >> > </bean>
> >> > <bean id="LocalServiceService"
> >> > class="ch.myexample.services.LocalServiceImpl">
> >> > <property name="contactDao" ref="ContactDao" />
> >> > </bean>
> >> > <bean id="wicketApplication"
> class="ch.myexample.WicketApplication">
> >> > </bean>
> >> > </beans>
> >> >
> >> >
> >> > --
> >> > --applicationContext to here --
> >> >
> >> > and web.xml
> >> >
> >> > <context-param>
> >> > <param-name>contextConfigLocation</param-name>
> >> > <param-value> classpath:applicationContext.xml</param-value>
> >> > </context-param>
> >> > <filter>
> >> > <filter-name>wicket.WebProject</filter-name>
> >> > <filter-class>org.apache.wicket.protocol.http.WicketFilter
> >> > </filter-class>
> >> > <init-param>
> >> > <param-name>applicationFactoryClassName
> >> > </param-name>
> >> > <param-value>
> >> > org.apache.wicket.spring.SpringWebApplicationFactory
> >> > </param-value>
> >> > </init-param>
> >> > <init-param>
> >> > <param-name>applicationBean</param-name>
> >> > <param-value> wicketApplication</param-value>
> >> > </init-param>
> >> > </filter>
> >> > <filter>
> >> > <filter-name>opensessioninview</filter-name>
> >> > <filter-class>
> >> >
> >> > org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
> >> > </filter-class>
> >> > </filter>
> >> > <filter-mapping>
> >> > <filter-name>opensessioninview</filter-name>
> >> > <url-pattern>/*</url-pattern>
> >> > </filter-mapping>
> >> > <filter-mapping>
> >> > <filter-name>wicket.WebProject</filter-name>
> >> > <url-pattern>/*</url-pattern>
> >> > </filter-mapping>
> >> > <listener>
> >> >
> >> > <listener-class>org.springframework.web.context.ContextLoaderListener
> >> > </listener-class>
> >> > </listener>
> >> > </web-app>
> >> >
> >> >
> >> > Could you tell me where is my mistake please
> >> >
> >> > Cheers
> >> >
> >> > --Richard
> >> >
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: org.hibernate.HibernateException: createCriteria is not valid
without active transaction
Posted by James Carman <jc...@carmanconsulting.com>.
Put it on the impl class.
On Sat, May 8, 2010 at 7:43 AM, Richard Slide <ri...@gmail.com> wrote:
> Yes i did it...
> this is DAO and impl
>
>
>
>
> public interface Dao<T extends DomainObject> {
>
> @Transactional
> void delete(T o);
>
> T load(long id);
>
> @Transactional
> void save(T o);
>
> @Transactional
> List<T> findAll();
>
> int countAll();
> }
>
> and the implemetation is
>
> public abstract class AbstractHibernateDaoImpl<T extends DomainObject>
> implements Dao<T> {
>
> private Class<T> domainClass;
>
> private SessionFactory sf;
>
> public AbstractHibernateDaoImpl(Class<T> domainClass) {
> this.domainClass = domainClass;
> }
>
> public SessionFactory getSessionFactory() {
> return sf;
> }
>
> public void setSessionFactory(SessionFactory sf) {
> this.sf = sf;
> }
>
> public void delete(T object) {
> getSession().delete(object);
> }
>
> @SuppressWarnings("unchecked")
> public T load(long id) {
> return (T) getSession().get(domainClass, id);
> }
>
> public void save(T object) {
> getSession().saveOrUpdate(object);
> }
>
> @SuppressWarnings("unchecked")
> public List<T> findAll() {
> Criteria criteria = getSession().createCriteria(domainClass);
> return (List<T>) criteria.list();
> }
>
> public int countAll() {
> Criteria criteria = getSession().createCriteria(domainClass);
> criteria.setProjection(Projections.rowCount());
> return (Integer) criteria.uniqueResult();
> }
>
> public Session getSession() {
> // presumes a current session, which we have through the
> // OpenSessionInViewFilter; doesn't work without that
> return sf.getCurrentSession();
> }
> }
>
>
>
>
> On Sat, May 8, 2010 at 12:05 PM, Karolina Rusin <il...@gmail.com>wrote:
>
>> Hello Richard,
>>
>> Maybe you need to use @Transactional above your dao method?
>> Hope this helps.
>>
>> Best regards,
>> Karolina Rusin
>>
>>
>> 2010/5/8 Richard Slide <ri...@gmail.com>
>>
>> > Hello all,
>> > i try to do a simple web application with the classic layout
>> > Wicket->Spring->Hibernate
>> >
>> > When i try to make a simple request i receive the following error.
>> >
>> > WicketMessage: Error attaching this container for rendering: [Page class
>> =
>> > ch.myexample.ListContacts, id = 0, version = 0]
>> > Root cause:
>> > org.hibernate.HibernateException: createCriteria is not valid without
>> > active
>> > transaction
>> >
>> > In IMHO all file conf seams to be correct correct... bat i don't
>> undestand
>> > hibenate dosen't find the correct session.
>> >
>> > At UI level i load the data with LoadableDetachableModel
>> >
>> > IModel contactsModel = new LoadableDetachableModel() {
>> > protected Object load() {
>> > return
>> > WicketApplication.get().getContactService().findAllContacts();
>> > }
>> > };
>> >
>> > --applicationContext from here --
>> >
>> > <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
>> > <property name="driverClassName">
>> > <value>${jdbc.driver}</value>
>> > </property>
>> > <property name="url">
>> > <value>${jdbc.url}</value>
>> > </property>
>> > <property name="username">
>> > <value>${jdbc.username}</value>
>> > </property>
>> > <property name="password">
>> > <value>${jdbc.password}</value>
>> > </property>
>> > </bean>
>> >
>> > <!-- hibernate session factory -->
>> > <bean id="sessionFactory"
>> >
>> >
>> >
>> class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
>> > <property name="dataSource" ref="dataSource" />
>> > <property name="hibernateProperties">
>> > <props>
>> > <prop key="hibernate.dialect">${hibernate.dialect}</prop>
>> > <prop key="hibernate.connection.pool_size">5</prop>
>> > <prop
>> > key="hibernate.current_session_context_class">thread</prop>
>> > <prop key="hibernate.show_sql">true</prop>
>> > <prop
>> > key="hibernate.cglib.use_reflection_optimizer">true</prop>
>> > <prop
>> >
>> >
>> key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
>> > <prop
>> > key="hibernate.hibernate.cache.use_query_cache">true</prop>
>> > </props>
>> > </property>
>> > <property name="annotatedClasses">
>> > <list>
>> > <value>
>> > ch.myexample.domain.Contact
>> > </value>
>> > </list>
>> > </property>
>> > </bean>
>> >
>> > <!-- setup transaction manager -->
>> > <bean id="transactionManager"
>> >
>> > class="org.springframework.orm.hibernate3.HibernateTransactionManager">
>> > <property name="sessionFactory">
>> > <ref bean="sessionFactory" />
>> > </property>
>> > </bean>
>> > <tx:annotation-driven />
>> > <bean id="ContactDao" class="ch.myexample.dao.impl.ContactDaoImpl">
>> > <property name="sessionFactory" ref="sessionFactory" />
>> > </bean>
>> > <bean id="LocalServiceService"
>> > class="ch.myexample.services.LocalServiceImpl">
>> > <property name="contactDao" ref="ContactDao" />
>> > </bean>
>> > <bean id="wicketApplication" class="ch.myexample.WicketApplication">
>> > </bean>
>> > </beans>
>> >
>> >
>> > --
>> > --applicationContext to here --
>> >
>> > and web.xml
>> >
>> > <context-param>
>> > <param-name>contextConfigLocation</param-name>
>> > <param-value> classpath:applicationContext.xml</param-value>
>> > </context-param>
>> > <filter>
>> > <filter-name>wicket.WebProject</filter-name>
>> > <filter-class>org.apache.wicket.protocol.http.WicketFilter
>> > </filter-class>
>> > <init-param>
>> > <param-name>applicationFactoryClassName
>> > </param-name>
>> > <param-value>
>> > org.apache.wicket.spring.SpringWebApplicationFactory
>> > </param-value>
>> > </init-param>
>> > <init-param>
>> > <param-name>applicationBean</param-name>
>> > <param-value> wicketApplication</param-value>
>> > </init-param>
>> > </filter>
>> > <filter>
>> > <filter-name>opensessioninview</filter-name>
>> > <filter-class>
>> >
>> > org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
>> > </filter-class>
>> > </filter>
>> > <filter-mapping>
>> > <filter-name>opensessioninview</filter-name>
>> > <url-pattern>/*</url-pattern>
>> > </filter-mapping>
>> > <filter-mapping>
>> > <filter-name>wicket.WebProject</filter-name>
>> > <url-pattern>/*</url-pattern>
>> > </filter-mapping>
>> > <listener>
>> >
>> > <listener-class>org.springframework.web.context.ContextLoaderListener
>> > </listener-class>
>> > </listener>
>> > </web-app>
>> >
>> >
>> > Could you tell me where is my mistake please
>> >
>> > Cheers
>> >
>> > --Richard
>> >
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: org.hibernate.HibernateException: createCriteria is not valid
without active transaction
Posted by Richard Slide <ri...@gmail.com>.
Yes i did it...
this is DAO and impl
public interface Dao<T extends DomainObject> {
@Transactional
void delete(T o);
T load(long id);
@Transactional
void save(T o);
@Transactional
List<T> findAll();
int countAll();
}
and the implemetation is
public abstract class AbstractHibernateDaoImpl<T extends DomainObject>
implements Dao<T> {
private Class<T> domainClass;
private SessionFactory sf;
public AbstractHibernateDaoImpl(Class<T> domainClass) {
this.domainClass = domainClass;
}
public SessionFactory getSessionFactory() {
return sf;
}
public void setSessionFactory(SessionFactory sf) {
this.sf = sf;
}
public void delete(T object) {
getSession().delete(object);
}
@SuppressWarnings("unchecked")
public T load(long id) {
return (T) getSession().get(domainClass, id);
}
public void save(T object) {
getSession().saveOrUpdate(object);
}
@SuppressWarnings("unchecked")
public List<T> findAll() {
Criteria criteria = getSession().createCriteria(domainClass);
return (List<T>) criteria.list();
}
public int countAll() {
Criteria criteria = getSession().createCriteria(domainClass);
criteria.setProjection(Projections.rowCount());
return (Integer) criteria.uniqueResult();
}
public Session getSession() {
// presumes a current session, which we have through the
// OpenSessionInViewFilter; doesn't work without that
return sf.getCurrentSession();
}
}
On Sat, May 8, 2010 at 12:05 PM, Karolina Rusin <il...@gmail.com>wrote:
> Hello Richard,
>
> Maybe you need to use @Transactional above your dao method?
> Hope this helps.
>
> Best regards,
> Karolina Rusin
>
>
> 2010/5/8 Richard Slide <ri...@gmail.com>
>
> > Hello all,
> > i try to do a simple web application with the classic layout
> > Wicket->Spring->Hibernate
> >
> > When i try to make a simple request i receive the following error.
> >
> > WicketMessage: Error attaching this container for rendering: [Page class
> =
> > ch.myexample.ListContacts, id = 0, version = 0]
> > Root cause:
> > org.hibernate.HibernateException: createCriteria is not valid without
> > active
> > transaction
> >
> > In IMHO all file conf seams to be correct correct... bat i don't
> undestand
> > hibenate dosen't find the correct session.
> >
> > At UI level i load the data with LoadableDetachableModel
> >
> > IModel contactsModel = new LoadableDetachableModel() {
> > protected Object load() {
> > return
> > WicketApplication.get().getContactService().findAllContacts();
> > }
> > };
> >
> > --applicationContext from here --
> >
> > <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
> > <property name="driverClassName">
> > <value>${jdbc.driver}</value>
> > </property>
> > <property name="url">
> > <value>${jdbc.url}</value>
> > </property>
> > <property name="username">
> > <value>${jdbc.username}</value>
> > </property>
> > <property name="password">
> > <value>${jdbc.password}</value>
> > </property>
> > </bean>
> >
> > <!-- hibernate session factory -->
> > <bean id="sessionFactory"
> >
> >
> >
> class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
> > <property name="dataSource" ref="dataSource" />
> > <property name="hibernateProperties">
> > <props>
> > <prop key="hibernate.dialect">${hibernate.dialect}</prop>
> > <prop key="hibernate.connection.pool_size">5</prop>
> > <prop
> > key="hibernate.current_session_context_class">thread</prop>
> > <prop key="hibernate.show_sql">true</prop>
> > <prop
> > key="hibernate.cglib.use_reflection_optimizer">true</prop>
> > <prop
> >
> >
> key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
> > <prop
> > key="hibernate.hibernate.cache.use_query_cache">true</prop>
> > </props>
> > </property>
> > <property name="annotatedClasses">
> > <list>
> > <value>
> > ch.myexample.domain.Contact
> > </value>
> > </list>
> > </property>
> > </bean>
> >
> > <!-- setup transaction manager -->
> > <bean id="transactionManager"
> >
> > class="org.springframework.orm.hibernate3.HibernateTransactionManager">
> > <property name="sessionFactory">
> > <ref bean="sessionFactory" />
> > </property>
> > </bean>
> > <tx:annotation-driven />
> > <bean id="ContactDao" class="ch.myexample.dao.impl.ContactDaoImpl">
> > <property name="sessionFactory" ref="sessionFactory" />
> > </bean>
> > <bean id="LocalServiceService"
> > class="ch.myexample.services.LocalServiceImpl">
> > <property name="contactDao" ref="ContactDao" />
> > </bean>
> > <bean id="wicketApplication" class="ch.myexample.WicketApplication">
> > </bean>
> > </beans>
> >
> >
> > --
> > --applicationContext to here --
> >
> > and web.xml
> >
> > <context-param>
> > <param-name>contextConfigLocation</param-name>
> > <param-value> classpath:applicationContext.xml</param-value>
> > </context-param>
> > <filter>
> > <filter-name>wicket.WebProject</filter-name>
> > <filter-class>org.apache.wicket.protocol.http.WicketFilter
> > </filter-class>
> > <init-param>
> > <param-name>applicationFactoryClassName
> > </param-name>
> > <param-value>
> > org.apache.wicket.spring.SpringWebApplicationFactory
> > </param-value>
> > </init-param>
> > <init-param>
> > <param-name>applicationBean</param-name>
> > <param-value> wicketApplication</param-value>
> > </init-param>
> > </filter>
> > <filter>
> > <filter-name>opensessioninview</filter-name>
> > <filter-class>
> >
> > org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
> > </filter-class>
> > </filter>
> > <filter-mapping>
> > <filter-name>opensessioninview</filter-name>
> > <url-pattern>/*</url-pattern>
> > </filter-mapping>
> > <filter-mapping>
> > <filter-name>wicket.WebProject</filter-name>
> > <url-pattern>/*</url-pattern>
> > </filter-mapping>
> > <listener>
> >
> > <listener-class>org.springframework.web.context.ContextLoaderListener
> > </listener-class>
> > </listener>
> > </web-app>
> >
> >
> > Could you tell me where is my mistake please
> >
> > Cheers
> >
> > --Richard
> >
>
Re: org.hibernate.HibernateException: createCriteria is not valid
without active transaction
Posted by Karolina Rusin <il...@gmail.com>.
Hello Richard,
Maybe you need to use @Transactional above your dao method?
Hope this helps.
Best regards,
Karolina Rusin
2010/5/8 Richard Slide <ri...@gmail.com>
> Hello all,
> i try to do a simple web application with the classic layout
> Wicket->Spring->Hibernate
>
> When i try to make a simple request i receive the following error.
>
> WicketMessage: Error attaching this container for rendering: [Page class =
> ch.myexample.ListContacts, id = 0, version = 0]
> Root cause:
> org.hibernate.HibernateException: createCriteria is not valid without
> active
> transaction
>
> In IMHO all file conf seams to be correct correct... bat i don't undestand
> hibenate dosen't find the correct session.
>
> At UI level i load the data with LoadableDetachableModel
>
> IModel contactsModel = new LoadableDetachableModel() {
> protected Object load() {
> return
> WicketApplication.get().getContactService().findAllContacts();
> }
> };
>
> --applicationContext from here --
>
> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
> <property name="driverClassName">
> <value>${jdbc.driver}</value>
> </property>
> <property name="url">
> <value>${jdbc.url}</value>
> </property>
> <property name="username">
> <value>${jdbc.username}</value>
> </property>
> <property name="password">
> <value>${jdbc.password}</value>
> </property>
> </bean>
>
> <!-- hibernate session factory -->
> <bean id="sessionFactory"
>
>
> class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
> <property name="dataSource" ref="dataSource" />
> <property name="hibernateProperties">
> <props>
> <prop key="hibernate.dialect">${hibernate.dialect}</prop>
> <prop key="hibernate.connection.pool_size">5</prop>
> <prop
> key="hibernate.current_session_context_class">thread</prop>
> <prop key="hibernate.show_sql">true</prop>
> <prop
> key="hibernate.cglib.use_reflection_optimizer">true</prop>
> <prop
>
> key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
> <prop
> key="hibernate.hibernate.cache.use_query_cache">true</prop>
> </props>
> </property>
> <property name="annotatedClasses">
> <list>
> <value>
> ch.myexample.domain.Contact
> </value>
> </list>
> </property>
> </bean>
>
> <!-- setup transaction manager -->
> <bean id="transactionManager"
>
> class="org.springframework.orm.hibernate3.HibernateTransactionManager">
> <property name="sessionFactory">
> <ref bean="sessionFactory" />
> </property>
> </bean>
> <tx:annotation-driven />
> <bean id="ContactDao" class="ch.myexample.dao.impl.ContactDaoImpl">
> <property name="sessionFactory" ref="sessionFactory" />
> </bean>
> <bean id="LocalServiceService"
> class="ch.myexample.services.LocalServiceImpl">
> <property name="contactDao" ref="ContactDao" />
> </bean>
> <bean id="wicketApplication" class="ch.myexample.WicketApplication">
> </bean>
> </beans>
>
>
> --
> --applicationContext to here --
>
> and web.xml
>
> <context-param>
> <param-name>contextConfigLocation</param-name>
> <param-value> classpath:applicationContext.xml</param-value>
> </context-param>
> <filter>
> <filter-name>wicket.WebProject</filter-name>
> <filter-class>org.apache.wicket.protocol.http.WicketFilter
> </filter-class>
> <init-param>
> <param-name>applicationFactoryClassName
> </param-name>
> <param-value>
> org.apache.wicket.spring.SpringWebApplicationFactory
> </param-value>
> </init-param>
> <init-param>
> <param-name>applicationBean</param-name>
> <param-value> wicketApplication</param-value>
> </init-param>
> </filter>
> <filter>
> <filter-name>opensessioninview</filter-name>
> <filter-class>
>
> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
> </filter-class>
> </filter>
> <filter-mapping>
> <filter-name>opensessioninview</filter-name>
> <url-pattern>/*</url-pattern>
> </filter-mapping>
> <filter-mapping>
> <filter-name>wicket.WebProject</filter-name>
> <url-pattern>/*</url-pattern>
> </filter-mapping>
> <listener>
>
> <listener-class>org.springframework.web.context.ContextLoaderListener
> </listener-class>
> </listener>
> </web-app>
>
>
> Could you tell me where is my mistake please
>
> Cheers
>
> --Richard
>