夢(mèng)幻之旅

          DEBUG - 天道酬勤

             :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            671 隨筆 :: 6 文章 :: 256 評(píng)論 :: 0 Trackbacks
          <?xml version="1.0" encoding="UTF-8" ?>
          <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi
          ="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation
          ="http://www.springframework.org/schema/beans 
              http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
          >
               
          <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
                  
          <property name="driverClass" value="com.mysql.jdbc.Driver" />
                  
          <property name="jdbcUrl" value="jdbc:mysql://127.0.0.1:3306/hwpok" />
                  
          <property name="user" value="mydata" />
                  
          <property name="password" value="root" />
                  
          <property name="autoCommitOnClose" value="true"/>
                  
          <property name="checkoutTimeout" value="5000"/>
                  
          <property name="initialPoolSize" value="2"/>
                  
          <property name="minPoolSize" value="2"/>
                  
          <property name="maxPoolSize" value="4"/>
                  
          <property name="maxIdleTime" value="25200"/>
                  
          <property name="acquireIncrement" value="1800"/>
                  
          <property name="maxIdleTimeExcessConnections" value="5"/>
              
          </bean>
              
          <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
                  
          <property name="dataSource" ref="dataSource" />
                  
          <property name="mappingDirectoryLocations">
                      
          <list>
                          
          <value>classpath:/hvp.spring.hibernate.orm</value>
                      
          </list>
                  
          </property>
                  
          <property name="hibernateProperties">
                      
          <props>
                          
          <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                          
          <prop key="hibernate.show_sql">true</prop>
                          
          <prop key="hibernate.generate_statistics">true</prop>
                      
          </props>
                  
          </property>
              
          </bean>
              
          <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
                  
          <property name="sessionFactory" ref="sessionFactory" />
              
          </bean>
              
          <bean id="userDAO" class="hvp.spring.hibernate.orm.UserDAO">
                  
          <property name="hibernateTemplate" ref="hibernateTemplate" />
              
          </bean>
          </beans>
          hbm.xml
          <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
          <hibernate-mapping package="hvp.spring.hibernate.orm">
              
          <class name="User" table="le_users">
                  
          <id name="userId" column="user_id">
                      
          <generator class="increment" />
                  
          </id>
                  
          <property name="userName" column="user_name" />
                  
          <property name="sex" column="sex" />
              
          </class>
          </hibernate-mapping>
          dao
          package hvp.spring.hibernate.orm;

          import org.springframework.context.ApplicationContext;
          import org.springframework.context.support.ClassPathXmlApplicationContext;
          import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

          public class UserDAO extends HibernateDaoSupport
          {   
              
          public void addUser(User user){
                  
          this.getHibernateTemplate().save(user);
              }

              
              
          public static void main(String[] a){
                  User user 
          = new User();
                  user.setUserName(
          "hwpokay");
                  user.setSex(
          0);
                  
                  String configPath 
          = "hvp/spring/aspectj/anno/beans.xml";
                  ApplicationContext ctx 
          = new ClassPathXmlApplicationContext(configPath);
                  
                  UserDAO userDAO 
          = (UserDAO)ctx.getBean("userDAO");
                  userDAO.addUser(user);
              }

          }

          posted on 2008-08-14 08:01 HUIKK 閱讀(557) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): Spring
          主站蜘蛛池模板: 耿马| 巴青县| 临潭县| 吉林省| 垦利县| 扎鲁特旗| 兰西县| 蓝田县| 容城县| 安福县| 名山县| 桂东县| 伊宁县| 亚东县| 新和县| 阿克陶县| 新巴尔虎右旗| 略阳县| 佛坪县| 施甸县| 临颍县| 托克托县| 鄂托克旗| 同心县| 渑池县| 沧州市| 宁远县| 镇赉县| 固原市| 鸡东县| 桂平市| 化德县| 邵武市| 双鸭山市| 饶平县| 萨迦县| 平定县| 阜阳市| 荣成市| 嘉祥县| 望谟县|