开发者

How to configure this code as spring Bean?

I have this code:

SessionFactory sessionFactory = new Configuration().configure("hibernate.cfg.xml");

How i may to configure this as bean? hibernate.cfg.xml contain this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory name="sessionFactory">
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.password">scott</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@x.x:1521:x</property>
        <property name="hibernate.connection.username">scott</property>
        <property name="hibernate.default_schema">SCOTT</property>
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
        <property name="hibernate.search.autoregister_listeners">false</property>
        <mapping resource="ormbyxml/domain/Emp.hbm.xml" />
        <mapping resource="ormbyxml/domain/SalaryLog.hbm.xml" />
        <mapping resource="ormbyxml/domain/Dept.hbm.xml" />
        <mapping resource="ormbyxml/domain/Salgrade.hbm.xml" />
        <mapping resource="ormbyxml/domain/Bonus.hbm.xml" />
    </s开发者_开发百科ession-factory>
</hibernate-configuration>


This is, of course, explained in the Spring reference documentation. See http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/orm.html#orm-session-factory-setup.

You may pass the path of your hibernate config file like this:

<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="configLocation" value="classpath:hibernate.cfg.xml"/>
</bean>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜