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 747395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:12:00+00:00 2026-05-14T14:12:00+00:00

I am trying to obtain Spring-defined Hibernate Configuration and SessionFactory objects in my non-Spring

  • 0

I am trying to obtain Spring-defined Hibernate Configuration and SessionFactory objects in my non-Spring code. The following is the definition in my applicationContext.xml file:

Code:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
   <property name="hibernateProperties">
    <props>
      <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
      <prop key="hibernate.show_sql">true</prop>
      <prop key="hibernate.hbm2ddl.auto">update</prop>
      <prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
      <prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
    </props>
   </property>
   <property name="dataSource">
    <ref bean="dataSource"/>
   </property>
    </bean>

If I now call getBean(“sessionFactory”), I am returned a $Proxy0 object which appears to be a proxy for the Hibernate SessionFactory object. But that isn’t what I want – I need the LocalSessionFactoryBean itself because I need access to the Configuration as well as the SessionFactory.

The reason I need the Configuration object is that our framework is able to use Hibernate’s dynamic model to automatically insert mappings at runtime; this requires that we change the Configuration and rebuild the SessionFactory. Really, all we’re trying to do is obtain the Hibernate config that already exists in Spring so that those of our customers that already have that information in Spring don’t need to duplicate it into a hibernate.cfg.xml file in order to use our Hibernate features.

  • 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-05-14T14:12:00+00:00Added an answer on May 14, 2026 at 2:12 pm

    One obscure feature of the Spring container is the & prefix:

    When you need to ask a container for
    an actual FactoryBean instance
    itself, not the bean it produces, you
    preface the bean id with the ampersand
    symbol & (without quotes) when
    calling the getBean method of the
    ApplicationContext. So for a given
    FactoryBean with an id of myBean,
    invoking getBean("myBean") on the
    container returns the product of the
    FactoryBean, and invoking
    getBean("&myBean") returns the
    FactoryBean instance itself.

    So in your case, using getBean("&sessionFactory") should return you the LocalSessionFactoryBean instance itself. Then you can call .getConfiguration() to get the Configuration object.

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

Sidebar

Related Questions

I am trying to obtain JSON object in the following code. The problem is,
I'm trying to obtain the size of a file before I download it. I
When trying to obtain an array of objects from an IEnumerable collection of objects
I'm trying to obtain data using regular expressions from a html file, by implementing
Trying to make a MySQL-based application support MS SQL, I ran into the following
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation
I'm trying to generate a class from an xsd schema but I obtain the
I'm trying to compile VC6 project with VC10... I obtain an error C2678 with
I am trying to use an http request to google maps to obtain the
I'm trying to obtain the base URL (hostname) of the server in which my

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.