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

  • Home
  • SEARCH
  • 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 7839915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:35:54+00:00 2026-06-02T15:35:54+00:00

my java project with spring and hibernate,can’t get the sessionFactory.it’s null all the time

  • 0

my java project with spring and hibernate,can’t get the sessionFactory.it’s null all the time when i use it. the configuration:

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
        <ref bean="dataSource" />
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">
                org.hibernate.dialect.Oracle9Dialect
            </prop>
        </props>
    </property>
</bean>

<bean id="test" class="test.Test">
    <property name="sessionFactory" ref="sessionFactory"></property>
</bean>`

the main code of Test.java is

        private SessionFactory sessionFactory;

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }
    public SessionFactory getSessionFacoty(){
        return this.sessionFactory;
    }
        public static void main(String[] args) {
    // TODO Auto-generated method stub
    Test test = new Test();
    System.out.println(test.sessionFactory);
}
  • 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-02T15:35:55+00:00Added an answer on June 2, 2026 at 3:35 pm

    Your test in the main method doesn’t actually use Spring for injection. You need to load the applicationContext.xml then get the test bean from that.

    So you could do something like this in your main:

    ApplicationContext context =
    new ClassPathXmlApplicationContext(new String[] {"applicationContext.xml"});
    
    Test test = (Test)context.getBean("test");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have spring project under java, using hibernate query, i like to use pessimistic
I was getting error like this in my hibernate, spring web project configuration: java.lang.NoClassDefFoundError:
We are working on Java web project based on JPA 2, Hibernate, Spring 3
I'm using Spring and Hibernate in a Java-EE application. The project is hosted at
My Java (JDK6) project uses Spring and JDBCTemplate for all its database access. We
I have web project based on Hibernate and Spring (programmatic configuration). The Hibernate mappings
i've been working on a project in java+maven+spring+hibernate and i wanted to automatically assign
I have a Java project connecting to an Ingres database and using the Spring
I have a Java project in Eclipse with ~10 packages and ~10 class files
I'm trying integrate spring with hibernate but catch exception on project start. Caused by:

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.