3 Replies Latest reply on Jun 4, 2008 8:08 PM by Mark Michalek

    Injecting hibernate session

    Binesh Gummadi Novice

      I configured hibernate with seam and I am able to inject session object into my action classes which have reference from xhtml files.

      *MyBookAction class*
      public class MyBookAction {
        @In(value = "cwDataSession")
        Session session;
      public void save() {
        // persisetence logic.
        // session object is not null here.

      <h:commandButton type="submit" value="Save" action="#{action.myaction.save}" />

      When I move the persistance logic to a DAO class the injection doesn't work anymore. Session object is always null.

      public class GenericHibernateDAO<T, ID extends Serializable> implements GenericDAO<T, ID> {
      private Session session;
      public void save() {
        // If I point my xhtml file to this method. Session object is injected.
        // <h:commandButton type="submit" value="Save" action="#{dao.hibernate_generic.save}" />

      Strangely if I change my xhtml to point to a method in DAO class, session is injected properly. But I don't want to reference my DAO in xhtml.

      I am using Seam 2.0.1GA and Hibernate 3.2.5GA. Deploying it is Jboss 4.2.2GA

      What am I doing wrong? Why do I see this strange behaviour?