Re: org.hibernate.HibernateException: createCriteria is not valid without active transaction

2010-05-08 Thread Richard Slide
I did it.

On Sat, May 8, 2010 at 2:00 PM, James Carman
wrote:

> Put it on the impl class.
>
> On Sat, May 8, 2010 at 7:43 AM, Richard Slide 
> wrote:
> > Yes i did it...
> > this is DAO and impl
> >
> >
> >
> >
> > public interface Dao {
> >
> >@Transactional
> >void delete(T o);
> >
> >T load(long id);
> >
> >@Transactional
> >void save(T o);
> >
> >@Transactional
> >List findAll();
> >
> >int countAll();
> > }
> >
> > and the implemetation  is
> >
> > public abstract class AbstractHibernateDaoImpl
> >implements Dao {
> >
> >  private Class domainClass;
> >
> >  private SessionFactory sf;
> >
> >  public AbstractHibernateDaoImpl(Class 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 findAll() {
> >Criteria criteria = getSession().createCriteria(domainClass);
> >return (List) 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  >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 
> >>
> >> > 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 --
> >> >
> >> > 
> >> >
> >> >${jdbc.driver}
> >> >
> >> >
> >> >${jdbc.url}
> >> >
> >> >
> >> >${jdbc.username}
> >> >
> >> >
> >> >${jdbc.password}
> >> >
> >> >
> >> >
> >> > 
> >> > >> >
> >> >
> >> >
> >>
> class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
> >> >
> >> >
> >> >
> >> > key="hibernate.dialect">${hibernate.dialect}
&

Re: org.hibernate.HibernateException: createCriteria is not valid without active transaction

2010-05-08 Thread Richard Slide
Yes i did it...
this is DAO and impl




public interface Dao {

@Transactional
void delete(T o);

T load(long id);

@Transactional
void save(T o);

@Transactional
List findAll();

int countAll();
}

and the implemetation  is

public abstract class AbstractHibernateDaoImpl
implements Dao {

  private Class domainClass;

  private SessionFactory sf;

  public AbstractHibernateDaoImpl(Class 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 findAll() {
Criteria criteria = getSession().createCriteria(domainClass);
return (List) 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 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 
>
> > 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 --
> >
> > 
> >
> >${jdbc.driver}
> >
> >
> >${jdbc.url}
> >
> >
> >${jdbc.username}
> >
> >
> >${jdbc.password}
> >
> >
> >
> > 
> > >
> >
> >
> class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
> >
> >
> >
> >${hibernate.dialect}
> >5
> > > key="hibernate.current_session_context_class">thread
> >true
> > > key="hibernate.cglib.use_reflection_optimizer">true
> > >
> >
> key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider
> > > key="hibernate.hibernate.cache.use_query_cache">true
> >
> >
> >
> >
> >
> >ch.myexample.domain.Contact
> >
> >
> >
> >
> >
> >
> > >
> > class="org.springframework.orm.hibernate3.HibernateTransactionManager">
> >
> >
> >
> >
> >
> >
> >
> >
> > > class="ch.myexample.services.LocalServiceImpl">
> >
> >
> >
> >
> > 
> >
> >
> > --
> > --applicationContext to here --
> >
> > and web.xml
> >
> > 
> >contextConfigLocation
> > classpath:applicationContext.xml
> >
> >
> >wicket.WebProject
> >org.apache.wicket.protocol.http.WicketFilter
> >
> >
> >applicationFactoryClassName
> >
> >
> > org.apache.wicket.spring.SpringWebApplicationFactory
> >
> >
> >
> >applicationBean
> > wicketApplication
> >
> >
> >
> >opensessioninview
> >
> >
> > org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
> >
> >
> >
> >opensessioninview
> >/*
> >
> >
> >wicket.WebProject
> >/*
> >
> >
> >
> > org.springframework.web.context.ContextLoaderListener
> >
> >
> > 
> >
> >
> > Could you tell me where is my mistake please
> >
> > Cheers
> >
> > --Richard
> >
>


org.hibernate.HibernateException: createCriteria is not valid without active transaction

2010-05-08 Thread Richard Slide
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 --



${jdbc.driver}


${jdbc.url}


${jdbc.username}


${jdbc.password}



 




${hibernate.dialect}
5
thread
true
true
org.hibernate.cache.EhCacheProvider
true





ch.myexample.domain.Contact























--
--applicationContext to here --

and web.xml


contextConfigLocation
 classpath:applicationContext.xml


wicket.WebProject
org.apache.wicket.protocol.http.WicketFilter


applicationFactoryClassName


org.apache.wicket.spring.SpringWebApplicationFactory



applicationBean
 wicketApplication



opensessioninview


org.springframework.orm.hibernate3.support.OpenSessionInViewFilter



opensessioninview
/*


wicket.WebProject
/*



org.springframework.web.context.ContextLoaderListener





Could you tell me where is my mistake please

Cheers

--Richard