title: Spring 3 Annotations - HibernateDaoSupport - Repository Requires Session Factory
body: <p>I am getting an exception saying : </p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException:
    'sessionFactory' or
    'hibernateTemplate' is required</p>
  </blockquote>
  
  <p>When trying to use the <code>@Repository</code> annotation on a HibernateDaoSupport class.  The error message is straightforward, in order to create the Repository it needs a sessionFactory.  However,I have defined a session factory in my XML:</p>
  
  <pre><code>&lt;!-- Hibernate --&gt;
      &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dashDataSource" /&gt;
          &lt;property name="annotatedClasses"&gt;
              &lt;list&gt;
                  &lt;value&gt;com.mycomp.myapp.Category&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>So I'm not sure how to give the repository the SessionFactory that it requires while it's creating it's annotation driven beans, I attempted to do the following:</p>
  
  <pre><code> @Autowired
      protected HibernateTemplate createHibernateTemplate(SessionFactory sessionFactory) {
          return super.createHibernateTemplate(sessionFactory);
      }
  </code></pre>
  
  <p>But this does not solve the problem, likely because the repository needs that property while instantiating, not just when performing an action.  Unfortunately, I don't know how to get around this problem because there are no constructors or initialization methods to override with a @Autowired annotation.</p>
  
  <p>I checked to make sure the sessionFactory bean is being created and can be Autowired, and that is fine.</p>