Cyh的博客

          Email:kissyan4916@163.com
          posts - 26, comments - 19, trackbacks - 0, articles - 220

          導航

          公告

          一直努力努力努力,像奴隸奴隸奴隸!~~
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          隨筆檔案(25)

          文章分類(219)

          文章檔案(220)

          新聞檔案(66)

          相冊

          收藏夾(7)

          最新隨筆

          搜索

          •  

          最新評論

          閱讀排行榜

          Spring+JPA自動生成Table配置

          Posted on 2009-02-16 21:08 啥都寫點 閱讀(1876) 評論(0)  編輯  收藏 所屬分類: J2EE

          在persistence.xml中加上<property name="hibernate.hbm2ddl.auto" value="update" />或設(shè)置在Spring配置中,在Spring 的sessionFactory中設(shè)置,當運行Spring時會自動生成Table

          <!--applicationContext.xml-->

          <?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 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
              xmlns:tx="http://www.springframework.org/schema/tx">


              <bean id="entityManagerFactory"
                  class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
                  <property name="persistenceUnitName" value="onlinephotoPU" />
              </bean>
              <bean id="transactionManager"
                  class="org.springframework.orm.jpa.JpaTransactionManager">
                  <property name="entityManagerFactory"
                      ref="entityManagerFactory" />
              </bean>

              <bean id="dataSource"
                  class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                  <property name="driverClassName" value="com.mysql.jdbc.Driver" />
                  <property name="url" value="jdbc:mysql://127.0.0.1:3306/photo" />
                  <property name="username" value="root" />
                  <property name="password" value="root" />
              </bean>
              <bean id="sessionFactory"
                  class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
                  <property name="dataSource" ref="dataSource" />
                  <property name="annotatedClasses">
                      <list>
                          <value>com.tst.Person</value>
                      </list>
                  </property>
                  <property name="hibernateProperties">
                      <props>
                          <prop key="hibernate.dialect">
                              org.hibernate.dialect.MySQLInnoDBDialect
                          </prop>
                          <prop key="hibernate.show_sql">true</prop>
                          <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
                      </props>
                  </property>
              </bean>
              
          <tx:annotation-driven transaction-manager="transactionManager" />
              <bean id="PersonDAO" class="com.tst.PersonDAO">
                  <property name="entityManagerFactory"
                      ref="entityManagerFactory" />
              </bean>

          </beans>

          <!--persistence.xml-->
          <?xml version="1.0" encoding="UTF-8"?>
          <persistence xmlns="http://java.sun.com/xml/ns/persistence"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
              http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
             
              <persistence-unit name="onlinephotoPU"
                  transaction-type="RESOURCE_LOCAL">
                  <provider>org.hibernate.ejb.HibernatePersistence</provider>
                  <class>com.tst.Person</class>
                  <properties>
                      <property name="hibernate.connection.driver_class"
                          value="com.mysql.jdbc.Driver" />
                      <property name="hibernate.connection.url"
                          value="jdbc:mysql://127.0.0.1:3306/photo" />
                      <property name="hibernate.connection.username" value="root" />
                      <property name="hibernate.connection.password" value="root" />
                      <property name="hibernate.hbm2ddl.auto" value="update" />
                  </properties>
              </persistence-unit>
          </persistence>



                                                                                                                 --    學海無涯
                  

          主站蜘蛛池模板: 时尚| 合山市| 蒙山县| 宝鸡市| 大姚县| 绥中县| 临澧县| 静乐县| 政和县| 合阳县| 乌兰察布市| 彝良县| 贡嘎县| 长子县| 丰原市| 阳谷县| 分宜县| 榆树市| 鄂温| 镇雄县| 崇阳县| 额尔古纳市| 石狮市| 鄂托克前旗| 南澳县| 沙河市| 岚皋县| 中牟县| 鹰潭市| 昭觉县| 漾濞| 郴州市| 波密县| 文化| 淮北市| 文昌市| 奉节县| 平利县| 汉中市| 安多县| 洪雅县|