BlogJava 联系 聚合 管理  

Blog Stats

随笔档案(17)

文章档案(1)


GaoWei

package hibernate;

public class Useinfo {
   private String username;
   private String userpass;
public String getUsername() {
 return username;
}
public void setUsername(String username) {
 this.username = username;
}
public String getUserpass() {
 return userpass;
}
public void setUserpass(String userpass) {
 this.userpass = userpass;
}
}


package hibernate;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

 


public class UseinfoDao extends HibernateDaoSupport {
 
 public void sava(Useinfo u)
 {
  getHibernateTemplate().saveOrUpdate(u);
 }
}


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>

 

 <mapping resource="hibernate.useinfo.hbm.xml" />

</session-factory>

</hibernate-configuration>



spring.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="sessionFactory"
           class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
           <property name="dataSource" ref="dataSource"/>
           <property name="mappingResources">
             <list>
                <value>hibernate/useinfo.hbm.xml</value>
             </list>
           </property>
          
           <property name="hibernateProperties">
                   <props>
                      <prop key="hibernate.dialect">
                          org.hibernate.dialect.MySQLMyISAMDialect
                      </prop>
                      <prop key="hibernate.show_sql">
                            true
                      </prop>
                   </props>
           </property>
      </bean>
     
      <bean id="useinfoDao"
            class="hibernate.UseinfoDao">
          
            <property name="sessionFactory" ref="sessionFactory"/>
            </bean>
     
    <!--  连接信息配置 -->
    <bean
        id="PlaceholderConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property
            name="locations"
            value="classpath:jdbc.properties"/>
    </bean>
    <bean
        id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property
            name="driverClassName"
            value="${jdbc.driver}" />
        <property
            name="username"
            value="${jdbc.user}" />
        <property
            name="password"
            value="${jdbc.password}" />
        <property
            name="url"
            value="${jdbc.url}" />
        <property
            name="initialSize"
            value="${jdbc.initialSize}" />
        <property
            name="maxActive"
            value="${jdbc.maxActive}" />
        <property
            name="maxIdle"
            value="${jdbc.maxIdle}" />
        <property
            name="maxWait"
            value="${jdbc.maxWait}" />
        <property
            name="minIdle"
            value="${jdbc.minIdle}" />
    </bean>
   
  
</beans>




useinfo.hbm.xml
<?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="hibernate.Useinfo" table="useinfo">
       <id name="username" column="username"></id>
        <property name="userpass"/>
    </class>

</hibernate-mapping>

jdbc.driver     =com.mysql.jdbc.Driver
jdbc.url        =jdbc:mysql://192.168.100.201/test
jdbc.user       =root
jdbc.password   =

jdbc.initialSize = 5
jdbc.maxActive  = 60
jdbc.maxIdle  = 10
jdbc.maxWait  = 50
jdbc.minIdle  = 5

#hibernate
hibernate.dialect                =    org.hibernate.dialect.MySQLDialect
#hibernate.dialect                =    org.hibernate.dialect.Oracle9Dialect
hibernate.show_sql                =    true
hibernate.format_sql            =    true
hibernate.hbm2ddl.auto            =    create-drop
#hibernate.hbm2ddl.auto            =    update
hibernate.cache.use_query_cache    =    false
hibernate.cache.provider_class    =    org.hibernate.cache.OSCacheProvider







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

     <bean id="dao" class="Dao">
           <property name="sessionFactory" ref="sessionFactory"/>
     </bean>
     <bean
        id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
        parent="abstractSessionFactory">
        <property name="annotatedClasses">
            <list>
                <value>Account</value>
            </list>
        </property>
    </bean>
   
    <bean
        id="abstractSessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
        abstract="true">
        <property
            name="dataSource"
            ref="dataSource" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
                <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
                <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
                <prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
            </props>
        </property>
       
        <property
            name="lobHandler"
            ref="oracleLobHandler" />
    </bean>
   
    <bean
        id="defaultLobHandler"
        class="org.springframework.jdbc.support.lob.DefaultLobHandler"
        lazy-init="true" />
    <bean
        id="oracleLobHandler"
        class="org.springframework.jdbc.support.lob.OracleLobHandler"
        lazy-init="true">
        <property name="nativeJdbcExtractor">
            <bean
                class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"
                lazy-init="true" />
        </property>
    </bean>
 
  <bean
        id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property
            name="sessionFactory"
            ref="sessionFactory" />
    </bean>
    <!--
     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
       <property name="dataSource" ref="dataSource"/>
       <property name="mappingResources">
                 <list>
                        <value>Account.xml</value>
                 </list>
       </property>
      
       <property name="hibernateProperties">
                   <props>
                      <prop key="hibernate.dialect">
                          org.hibernate.dialect.MySQLMyISAMDialect
                      </prop>
                      <prop key="hibernate.show_sql">
                            true
                      </prop>
                       <prop key="hibernate.hbm2ddl.auto">
                       create-drop
                      </prop>
                   </props>
           </property>
     </bean>
     -->
<!--  连接信息配置 -->
    <bean
        id="PlaceholderConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property
            name="locations"
            value="classpath:jdbc.properties"/>
    </bean>
    <bean
        id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property
            name="driverClassName"
            value="${jdbc.driver}" />
        <property
            name="username"
            value="${jdbc.user}" />
        <property
            name="password"
            value="${jdbc.password}" />
        <property
            name="url"
            value="${jdbc.url}" />
        <property
            name="initialSize"
            value="${jdbc.initialSize}" />
        <property
            name="maxActive"
            value="${jdbc.maxActive}" />
        <property
            name="maxIdle"
            value="${jdbc.maxIdle}" />
        <property
            name="maxWait"
            value="${jdbc.maxWait}" />
        <property
            name="minIdle"
            value="${jdbc.minIdle}" />
    </bean>

</beans>




posted on 2006-10-19 11:59 gggg874 阅读(218) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: