You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by limonn <in...@limonn.com> on 2008/08/23 17:50:08 UTC

inyect Session not working for hibernate

Hi guys !

I m trying to expand one of the main tutorials 
http://www.infoq.com/articles/tapestry5-intro Tapestry for Nonbelievers 
bringing data from database through hibernate.

import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.tutorial.entities.User;
import org.apache.tapestry5.tutorial.services.UserDAO;
import org.hibernate.Session;


If I do at the start  class

            @Inject
	    private Session session;

public List<User> getUserList()
	    {
	      return session.createCriteria(User.class).list();
	    }

Works OK !!

but if I use the same at 

public class UserDAOImpl implements UserDAO {

    @Inject
    private Session session;  // Why  this is null ???????????
	
	
	public UserDAOImpl(){
		
	}
	
	public List<User> findAllUsers()
	{
	   return session.createCriteria(User.class).list();
	}

I get a null pointer exception at session because is null

Why session is null with the same inject annotation here and not there

then at the start class I wanted to do :

            @Inject
	    private UserDAO userDAO;

		public List<User> getUserList()
	    {
	       return userDAO.findAllUsers();
           }

but null pointer exception at UserDAOImpl

-----
Raul Rosenzvaig
www.limonn.com
-- 
View this message in context: http://www.nabble.com/inyect-Session-not-working-for-hibernate-tp19122647p19122647.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: inyect Session not working for hibernate

Posted by Sven Homburg <ho...@googlemail.com>.
you cant use the @Inject Annotation in other class types than pages,
components or mixins

2008/8/23 limonn <in...@limonn.com>

>
> Hi guys !
>
> I m trying to expand one of the main tutorials
> http://www.infoq.com/articles/tapestry5-intro Tapestry for Nonbelievers
> bringing data from database through hibernate.
>
> import org.apache.tapestry5.ioc.annotations.Inject;
> import org.apache.tapestry5.tutorial.entities.User;
> import org.apache.tapestry5.tutorial.services.UserDAO;
> import org.hibernate.Session;
>
>
> If I do at the start  class
>
>            @Inject
>            private Session session;
>
> public List<User> getUserList()
>            {
>              return session.createCriteria(User.class).list();
>            }
>
> Works OK !!
>
> but if I use the same at
>
> public class UserDAOImpl implements UserDAO {
>
>    @Inject
>    private Session session;  // Why  this is null ???????????
>
>
>        public UserDAOImpl(){
>
>        }
>
>        public List<User> findAllUsers()
>        {
>           return session.createCriteria(User.class).list();
>        }
>
> I get a null pointer exception at session because is null
>
> Why session is null with the same inject annotation here and not there
>
> then at the start class I wanted to do :
>
>            @Inject
>            private UserDAO userDAO;
>
>                public List<User> getUserList()
>            {
>               return userDAO.findAllUsers();
>           }
>
> but null pointer exception at UserDAOImpl
>
> -----
> Raul Rosenzvaig
> www.limonn.com
> --
> View this message in context:
> http://www.nabble.com/inyect-Session-not-working-for-hibernate-tp19122647p19122647.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
with regards
Sven Homburg
http://www.chenillekit.org
http://tapestry5-components.googlecode.com

Re: inyect Session not working for hibernate

Posted by Sven Homburg <ho...@googlemail.com>.
look for this sample
http://www.chenillekit.org/chenillekit-hibernate/doa_sample.html

2008/8/23 limonn <in...@limonn.com>

>
> Hi guys !
>
> I m trying to expand one of the main tutorials
> http://www.infoq.com/articles/tapestry5-intro Tapestry for Nonbelievers
> bringing data from database through hibernate.
>
> import org.apache.tapestry5.ioc.annotations.Inject;
> import org.apache.tapestry5.tutorial.entities.User;
> import org.apache.tapestry5.tutorial.services.UserDAO;
> import org.hibernate.Session;
>
>
> If I do at the start  class
>
>            @Inject
>            private Session session;
>
> public List<User> getUserList()
>            {
>              return session.createCriteria(User.class).list();
>            }
>
> Works OK !!
>
> but if I use the same at
>
> public class UserDAOImpl implements UserDAO {
>
>    @Inject
>    private Session session;  // Why  this is null ???????????
>
>
>        public UserDAOImpl(){
>
>        }
>
>        public List<User> findAllUsers()
>        {
>           return session.createCriteria(User.class).list();
>        }
>
> I get a null pointer exception at session because is null
>
> Why session is null with the same inject annotation here and not there
>
> then at the start class I wanted to do :
>
>            @Inject
>            private UserDAO userDAO;
>
>                public List<User> getUserList()
>            {
>               return userDAO.findAllUsers();
>           }
>
> but null pointer exception at UserDAOImpl
>
> -----
> Raul Rosenzvaig
> www.limonn.com
> --
> View this message in context:
> http://www.nabble.com/inyect-Session-not-working-for-hibernate-tp19122647p19122647.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
with regards
Sven Homburg
http://www.chenillekit.org
http://tapestry5-components.googlecode.com