spring整合hiberante如何取得设置的hibernateProperties

Spring2.5 整合 Hibernate3 时,我想在dao中取得配置文件中设置的hibernateProperties,找了很久都没找到方法.

配置如下:
[code="java"] class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

    <property name="mappingDirectoryLocations"><!-- mappingResources -->
        <list>
            <value>WEB-INF/classes/com/etone/solid/po/</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">
                org.hibernate.dialect.SybaseDialect
            </prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.format_sql">true</prop>
            <prop key="hibernate.cache.use_query_cache">true</prop>
            <prop key="hibernate.jdbc.fetch_size">50</prop>
            <prop key="hibernate.jdbc.batch_size">0</prop>
            <prop key="use_streams_for_binary">true</prop>
            <prop key="hibernate.cache.provider_class">
                org.hibernate.cache.EhCacheProvider
            </prop>
            <prop key="hibernate.query.factory_class">
                org.hibernate.hql.classic.ClassicQueryTranslatorFactory
            </prop>
            <prop key="hibernate.generate_statistics">true</prop>
            <prop key="hibernate.connection.release_mode">
                auto
            </prop>
            <!-- prop key="hibernate.hbm2ddl.auto">create-drop</prop-->
            <!-- prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
                <prop key="hibernate.proxool.xml">/WEB-INF/proxool.xml</prop>
                <prop key="hibernate.proxool.pool_alias">spring</prop-->
        </props>
    </property>

    <property name="eventListeners">
        <map>
            <entry key="merge">
                <bean
                    class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener" />
            </entry>
        </map>
    </property>
</bean>[/code]

谢谢哪位帮忙回答一下
[b]问题补充:[/b]
我拿到的sessionFactory是org.hibernate.SessionFactory,

我看了下,org.springframework.orm.hibernate3.LocalSessionFactoryBean才有getHibernateProperties方法.

我怎么才能得到org.springframework.orm.hibernate3.LocalSessionFactoryBean实例呢?
[b]问题补充:[/b]
to lovewhzlq:
[i]得到工厂本身的话,就注入"&sessionFactory"[/i]
我这样写:
[code="java"] class="com.etone.common.dao.impl.DaoSupportHibernate3Impl">



[/code]
报错:
[code="java"]
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 207 in XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: The reference to entity "sessionFactory" must end with the ';' delimiter.
[/code]

[color=red]请问这个注入怎么写?[/color]

to xuzhfa123:
[i]Hibernate具体版本号?再查看Spring2.5支持你那个版本不[/i]

整合成功,使用的版本是spring2.5.6 + hibernate3.3.2 + struts 2.1.6

to rain2005:
强制转化应该不行的吧?两个Bena不同.
由于在Dao中使用,我不想通过getBean("sessionFactory")形式来取.

[b]问题补充:[/b]
to lovewhzlq:
我这要写了
[code="java"]
class="com.etone.common.dao.impl.DaoSupportHibernate3Impl">






[/code]
报另一个错误:
[code="java"]
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 210 in XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.1: '&sessionFactory' is not a valid value for 'NCName'.
[/code]

[b]问题补充:[/b]
我刚才试了一下,找到了一个可以的方法,但感觉不太好..
如下:
在DaoSupportHibernate3Impl中定义增加:
[quote] private SessionFactoryImpl sessionFactoryImpl;
public SessionFactoryImpl getSessionFactoryImpl() {
return sessionFactoryImpl;
}

public void setSessionFactoryImpl(SessionFactoryImpl sessionFactoryImpl) {
    this.sessionFactoryImpl = sessionFactoryImpl;
}[/quote]

XML配置:
[code="java"]
class="com.etone.common.dao.impl.DaoSupportHibernate3Impl">







[/code]
在DaoSupportHibernate3Impl中这样使用:
[code="java"]sessionFactoryImpl.getSettings().isScrollableResultSetsEnabled();[/code]

不知道有无更好的方法?
[b]问题补充:[/b]
谢谢各位的热心解答!
我想应该就是各位所说的方法了:

1,注入sessionFactory到org.hibernate.impl.SessionFactoryImpl实例变量
2.通过ApplicationContext来得到.

暂时我是用第1种方法.

那看来不能这么注入,

这种方式是看来只能通过getBean("&sessionFactory")的方式来得到工厂对象本身,没办法,
只能实现ApplicationContextAware之类的接口得到整个ioc容器,再得到它了,

如果是web应用的话,那可以用org.springframework.web.context.support.WebApplicationContextUtils来得到ApplicationContext,就不用依赖spring的接口了

你得到sessionFactory这个bean嘛
再调用它的public Properties getHibernateProperties()方法就得到了

得到工厂本身的话,就注入"[color=red]&[/color]sessionFactory"

Hibernate具体版本号?再查看Spring2.5支持你那个版本不

强制转化成LocalSessionFactoryBean

或者让DAO实现
implements ApplicationContextAware接口
[code="java"]public void setApplicationContext(ApplicationContext arg0) throws BeansException {

this.ctx=arg0;

} [/code]
有了这个ctx你就可以通过getBean("sessionFactory")取到LocalSessionFactoryBean了

<bean id="daoSupport"
    class="com.etone.common.dao.impl.DaoSupportHibernate3Impl">
    <property name="sessionFactory">
        <ref local[color=red]="&amp;sessionFactory"[/color] />
    </property>
</bean>

这样写,xml中不能直接写&

这样挺好的啊,改动也不大,也可以考虑把hibernateProperties放到配置文件里面,然后在bean里面使用占位符的方式。