The Hibernate session session is still null in my DAO for a regular java class


I see so many questions on this and have tried numerous permutations of the many different solutions and none have worked.

I have a dao that requires a hibernate sessionfactory to do transactions. In the SpringMVC Context I've seen it working but the dao included in a java class is null. There is no error in catalina.out:

my full applicationContext.xml(because I really think the problem is here somewhere):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""


<!-- Scan classpath for annotations (eg: @Service, @Repository etc)-->


<context:component-scan base-package="com.shazam.di.*" />

<!-- JNDI Data Source. this works I can get to it independent of spring-->
<bean id="myDataSource" class="org.springframework.jndi.JndiObjectFactoryBean"
    <property name="jndiName" value="jdbc/dostudentdb"/>
    <property name="resourceRef" value="true"/>


<!-- Hibernate Session Factory -->
<bean id="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="myDataSource"/>
    <property name="packagesToScan">
    <property name="hibernateProperties">
            <prop key="hibernate.show_sql">false</prop>
            <!--<prop key="">update</prop>-->
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>

<!-- Hibernate Transaction Manager -->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="mySessionFactory"/>

<!--I've alternated between contructor, properties for getters & setters -->
<!--here, and nothing (just letting it get autowired into the private-->
<!--SessionFactory instance, no effing cigar!!-->
<bean id="studentDAO" class="org.shazam.di.spring.coursemgmt.dao.StudentDAO">
    <!--<constructor-arg type="SessionFactory" value="mySessionFactory"/>-->
    <property name="insertUserProfile" ref="insertUserProfile"/>

The class for which the DAO but not the sessionFactory can be found:

public class CheckClassAccess
    private static StudentDAO studentDAO;...

The beginning of the DAO(tried autwiring only getter & setters and a constructor):

@SuppressWarnings({"unchecked", "rawtypes"})
public class StudentDAO {

    private SessionFactory sessionFactory;

The WEB XML Spring lines:

and then a little later...

The only other caveat to this is that I'm attempting to get this to work within an opensource java cms called Opencms. But not sure that's relevant as the files that I'm wiring to are vanilla java support class, not controllers or anything(not really looking to do Spring-MVC with it just yet).

In fact all of this works in a Spring MVC servlet-context on a seperate smaller application but I just cannot seem to get these same objects/annotations to register in the applicationContext.

If you are using annotations naming matters. So change your StudentDAO as following:

private SessionFactory sessionFactory;

Look at this for more explanation.

Alternatively Spring recommends @Resource annotation:

private SessionFactory sessionFactory;