首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

spring+hibernate调整配置

2012-08-29 
spring+hibernate整合配置#config/jdbchibernate.cfghibernate.cfg.xmljdbc.serveryourServerjdbc.port

spring+hibernate整合配置
#config/jdbc
hibernate.cfg=hibernate.cfg.xml

jdbc.server=yourServer
jdbc.port=port
jdbc.dbname=yourDBName
jdbc.username=yourUserName
jdbc.password=yourPW

jdbc.driverClassName=Driver
jdbc.url=

hibernate.dialect=

config/hibernate
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="com.hcao.bean.Customer"  table="customer" >
        <id name="id" type="int">
            <column name="id" />
            <generator />
        </id>
        <property name="firstName" type="string">
            <column name="first_name" not-null="false" />
        </property>
        <property name="lastName" type="string">
            <column name="last_name" not-null="false" />
        </property>
        <property name="age" type="java.lang.Short">
            <column name="age" not-null="false" />
        </property>
        <property name="gender" type="char">
            <column name="gender" not-null="false" />
        </property>
    </class>

</hibernate-mapping>

config/hibernate/hibernate.cfg.xml
<?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>
    <property name="hibernate.show_sql">false</property>
        <property name="hibernate.dialect">org.hibernate.dialect.SybaseDialect</property>
        <property name="hibernate.cache.use_second_level_cache">false</property>
        <property name="hibernate.jdbc.batch_size">40</property>

        <mapping resource="Facility.hbm.xml" />
        <mapping resource="Customer.hbm.xml" />
        <mapping resource="namedQueries.hbm.xml" />
       
    </session-factory>
</hibernate-configuration>


jdbc-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
    <bean id="placeholderConfig"
          destroy-method="close">
<property name="driverClassName"   value="${jdbc.driverClassName}"/>
<property name="url"               value="${jdbc.url}"/>
<property name="username"          value="${jdbc.username}"/>
<property name="password"          value="${jdbc.password}"/>
    </bean>

    <!-- ================= configure Hibernate ================== -->
    <bean id="sessionFactory" ref="dataSource"/>
<property name="configLocation" value="${hibernate.cfg}"/>
<property name="hibernateProperties">
    <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.${hibernate.dialect}</prop>
            </props>
        </property>
    </bean>

<!-- ===================configure DAO ========================= -->
    <bean id="genericDao" >
          <property name="sessionFactory" ref="sessionFactory" />
    </bean>
   
    <bean id="genericService" >
    <property name="dao" ref="genericDao" />
    </bean>

</beans>



context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

<import resource="jdbc-context.xml"/>

<!--  ========= property placeholder post-processor ========= -->
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>jdbc-${instance}.properties</value>
</list>
</property>
</bean>

</beans>



热点排行