title: org.hibernate.LazyInitializationException: could not initialize proxy - no Session?
body: <p>I am trying to make a simple load from an object from the DB, but i got the error "could not initialize proxy - no Session", Any idea ? Thanks</p>
  
  <pre><code>org.hibernate.LazyInitializationException: could not initialize proxy - no Session
      org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.jav a:167)
      org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:215)
      org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
      com.myapp.domain.User_$$_javassist_0.getLogin(User_$$_javassist_0.java)
      com.myapp.validator.UserFormValidator.validate(UserFormValidator.java:34)
  </code></pre>
  
  <hr>
  
  <pre><code>@Component 
  public class UserFormValidator implements Validator {
  
  @Autowired
  private UserDAO userDAO;  
  
  @Override
  public boolean supports(Class&lt;?&gt; clazz) {
      return UserForm.class.equals(clazz);
  }
  
  public UserDAO getUserDAO() {
      return userDAO;
  }
  
  public void setUserDAO(UserDAO userDAO) {
      this.userDAO = userDAO;
  }
  
  @Override
  public void validate(Object target, Errors errors) {
      User user = (User)getUserDAO().findById(new Integer(1));
      System.out.println ("User -&gt; " + user.getLogin());
  }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>@Transactional
  public class GenericDAOHibernateImpl &lt;T, PK extends Serializable&gt;
  implements GenericDAO&lt;T, PK&gt; {
  
  public GenericDAOHibernateImpl() {
      super();
  }
  
  private Class&lt;T&gt; type;
  
  @Resource(name = "sessionFactory")
  private SessionFactory sessionFactory;
  
  public GenericDAOHibernateImpl(Class&lt;T&gt; type) {
      this.type = type;
  }
  
  public void saveOrUpdate(T object) {
      getSession().save(object);
  }
  
  public Object findById(Serializable id) {
       return getSession().load(type, id);
  }
  
  protected Session getSession() {
      return sessionFactory.getCurrentSession();
  }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans  xmlns="http://www.springframework.org/schema/beans" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:p="http://www.springframework.org/schema/p" 
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/tx 
          http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-3.0.xsd
          "&gt;
  
  &lt;context:property-placeholder location="/WEB-INF/jdbc.properties" /&gt;
  
  &lt;!-- Enable annotation style of managing transactions --&gt;
  &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;   
  
  &lt;!-- Declare the Hibernate SessionFactory for retrieving Hibernate sessions --&gt;
  &lt;!-- See http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/orm/hibernate3/annotation/AnnotationSessionFactoryBean.html --&gt;                           
  &lt;!-- See http://docs.jboss.org/hibernate/stable/core/api/index.html?org/hibernate/SessionFactory.html --&gt;
  &lt;!-- See http://docs.jboss.org/hibernate/stable/core/api/index.html?org/hibernate/Session.html --&gt;
  
  &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
               p:dataSource-ref="dataSource"
               p:configLocation="classpath:hibernate.cfg.xml"
               p:packagesToScan="com.myapp.domain"/&gt;  
  
  &lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" 
  destroy-method="close" 
  p:driverClass="${jdbc.driverClassName}" 
  p:jdbcUrl="${jdbc.url}"
  p:user="${jdbc.username}"
  p:password="${jdbc.password}"
  p:acquireIncrement="5"
              p:idleConnectionTestPeriod="60"
              p:maxPoolSize="100"
              p:maxStatements="50"
              p:minPoolSize="10" 
  /&gt;
  
  
  &lt;!-- Declare a transaction manager--&gt;
  &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" 
              p:sessionFactory-ref="sessionFactory" /&gt;
  </code></pre>
  
  <p></p>
  
  <hr>
  
  <pre><code>@Entity
  @Table(name="USER")
  public class User extends appEntity {
  
  @Id
  @Column(name = "USER_ID", unique = true, nullable = false)
  private Integer id;
  @Column(name = "LOGIN")
  private String login;
  @Column(name = "PASSWORD")
  private String password;
  
  
  public String getLogin() {
      return login;
  }
  public void setLogin(String login) {
      this.login = login;
  }
  
  public Integer getId() {
      return id;
  }
  public void setId(Integer id) {
      this.id = id;
  }
  public String getPassword() {
      return password;
  }
  public void setPassword(String password) {
      this.password = password;
  }
  </code></pre>