Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8092417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:16:45+00:00 2026-06-05T20:16:45+00:00

I’m having issues properly setting up my Hibernate configuration. After trying to extend the

  • 0

I’m having issues properly setting up my Hibernate configuration. After trying to extend the HibernateDaoSupport into a GenericDao and extending those to class-specific daos, but when I call findByNamedQuery in my dao, getSession() throws an NPE.

When I tried switching to extending HibernateTemplate, the hibernateTemplate doesn’t get instantiated properly, and is still null:

java.lang.NullPointerException
at org.springframework.orm.hibernate3.support.HibernateDaoSupport.getSession(HibernateDaoSupport.java:143)
at com.jmt.hibernate.dao.GenericDaoImpl.findByNamedQuery(GenericDaoImpl.java)

What am I missing??

I used maven2 to build the project,
1. added the hibernate plugin into my pom.xml:

   <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>hibernate3-maven-plugin</artifactId>
    <version>3.0</version>

    <configuration>
        <components>
            <component>
            <name>hb2ddl</name>
            <implementation>jpaconfiguration</implementation>
            </component>
        </components>
        <componentProperties>
        <drop>true</drop>
        <outputfilename>output.sql</outputfilename>
        <format>false</format>
        <persistenceunit>MyEntityManager</persistenceunit>
        <ejb3>true</ejb3>
        </componentProperties>

    </configuration>
</plugin>

2. defined my entity manager in persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">

   <persistence-unit name="MyEntityManager" transaction-type="RESOURCE_LOCAL"> <!-- "JTA"> -->
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/DefaultDS</jta-data-source>

        <class>com.jmt.model.UserEntity</class>

      <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
      <validation-mode>CALLBACK</validation-mode>
      <properties>

            <property name="hibernate.archive.autodetection" value="class"/>
            <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
         <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/><!-- org.hibernate.dialect.HSQLDialect" -->
         <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
         <property name="hibernate.connection.url"  value="${jdbc.url}"/>
         <property name="hibernate.connection.username" value="${jdbc.username}"/>
         <property name="hibernate.connection.password" value="${jdbc.password}"/>

      </properties>
   </persistence-unit>
</persistence>

3. wired up my daos in applicationContext.xml:

 <bean id="hibernateDaoSupport" abstract="true"
class="org.springframework.orm.hibernate3.support.HibernateDaoSupport">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
    <bean id="hibernateHelper" class="org.springframework.orm.hibernate3.HibernateTemplate" >
        <constructor-arg ref="sessionFactory"/>
    </bean>
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
    <property name="hibernateManagedSession" value="true"/>
</bean>

    <bean class="com.jmt.model.UserEntity"/>

    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />

    <bean
        class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
        <property name="order" value="1" />
    </bean>

    <bean
        class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
        <property name="order" value="2" />
    </bean>

    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
            <property name="basename"><value>messages</value></property>
    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="org.postgresql.Driver"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="poolPreparedStatements" value="true"/>
        <property name="defaultAutoCommit" value="true"/>
        <property name="maxActive" value="100"/>
        <property name="maxIdle" value="30"/>
        <property name="maxWait" value="1000"/>
        <property name="removeAbandoned" value="true"/>
        <property name="removeAbandonedTimeout" value="60"/>
        <property name="logAbandoned" value="true"/>
        <property name="testOnBorrow" value="false"/>
        <property name="testWhileIdle" value="true"/>
        <property name="timeBetweenEvictionRunsMillis" value="10000"/>
        <property name="minEvictableIdleTimeMillis" value="60000"/>        
    </bean>   


    <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                <prop key="hibernate.query.substitutions">true 'Y', false 'N'</prop>
                <prop key="hibernate.jdbc.batch_size">15</prop>   
                <prop key="hibernate.connection.isolation">2</prop>
            </props>       
        </property>
         <property name="packagesToScan">
            <list>
                <value>com.jmt.model</value>
                <value>com.jmt.hibernate.dao</value>
            </list>
        </property>        
    </bean>
    <bean id="userDao" class="com.jmt.hibernate.dao.UserDaoImpl">
        <constructor-arg value="com.jmt.hibernate.dao.UserDaoImpl"/>
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

4. even added a filter into my web.xml hoping that would inject the session properly:

<filter>
        <filter-name>sessionLoadingFilter</filter-name>
        <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    </filter>  

I didn’t add in a manager yet, hoping that fewer layers would make SOMETHING work…

Any help/ideas would be much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:16:47+00:00Added an answer on June 5, 2026 at 8:16 pm

    Yuck, I did not think about where the call to the dao was being made, and yes, that’s why there wasn’t an open session. Someone had used spring dwr to call the dao directly from a jsp file. Once I got rid of that and made the call from my Controller, the session was finally being instantiated properly. Thanks for the help, Japs!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.