欧美成人午夜免费全部完,亚洲午夜福利精品久久,а√最新版在线天堂,另类亚洲综合区图片小说区,亚洲欧美日韩精品色xxx

Java培訓(xùn)之Spring4.3.14.RELEASE整合Hibernate5.2.10.Final

2018-04-19 13:40:43 1399瀏覽

USerDao層實現(xiàn)類不要繼承HibernateDaoSupport,現(xiàn)在Spring不推薦使用這種方式:

會報錯:org.hibernate.Session.getFlushMode()Lorg/hibernate/FlushMode;

使用Hibernate5.2.10.Final版本會報錯。使用Hibernate5.1.0.Final版本則不會報錯,總之推薦使用SessionFactory的方式來獲取Session:



代碼如下:UserDaoImpl

  @Repository
  publicclassUserDaoImplimplementsUserDao{
  @Autowired
  privateSessionFactorysessionFactory;
  @Override
  publicvoidadd(Stringusername){
  //TODOAuto-generatedmethodstub
  //Stringsql="insertintouser(username)values(?)";
  Useruser=newUser();
  user.setUsername(username);
  Sessionsession=sessionFactory.getCurrentSession();
  session.save(user);
  }
  }

Spring的xml配置文件

  <?xmlversion="1.0"encoding="UTF-8"?>
  <beansxmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:p="http://www.springframework.org/schema/p"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:aop="http://www.springframework.org/schema/aop"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/context
  http://www.springframework.org/schema/context/spring-context.xsd
  http://www.springframework.org/schema/aop
  http://www.springframework.org/schema/aop/spring-aop.xsd
  http://www.springframework.org/schema/tx
  http://www.springframework.org/schema/tx/spring-tx.xsd">
  <context:component-scanbase-package="com.servlet"></context:component-scan>
  <context:property-placeholderlocation="classpath:jdbc.properties"/>
  <!--配置C3p0連接池對象-->
  <beanid="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource">
  <propertyname="user"value="root"></property>
  <propertyname="password"value="root"></property>
  <propertyname="jdbcUrl"value="jdbc:mysql:///spring"></property>
  <propertyname="driverClass"value="com.mysql.jdbc.Driver"></property>
  <propertyname="maxPoolSize"value="200"></property>
  <propertyname="initialPoolSize"value="20"></property>
  </bean>
  <!--配置SessionFactory-->
  <beanid="sessionFactory"class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
  <!--引入數(shù)據(jù)源-->
  <propertyname="dataSource"ref="dataSource"></property>
  <propertyname="hibernateProperties">
  <props>
  <propkey="hibernate.show_sql">true</prop>
  <propkey="hibernate.format_sql">true</prop>
  <propkey="hibernate.hbm2ddl.auto">update</prop>
  <propkey="hibernate.connection.isolation">4</prop>
  <!--<propkey="current_session_context_class">thread</prop>
  --></props>
  </property>
  <propertyname="packagesToScan">
  <list>
  <value>com.servlet</value>
  </list>
  </property>
  </bean>
  <!--1.配置平臺事務(wù)管理器
  jdbc/Mybatis:DateSourceTransactionManager
  Hibernate:HibernateTransactionManager
  -->
  <beanid="transactionManager"class="org.springframework.orm.hibernate5.HibernateTransactionManager">
  <propertyname="sessionFactory"ref="sessionFactory"></property>
  </bean>
  <!--開啟事務(wù)注解-->
  <tx:annotation-driventransaction-manager="transactionManager"/>
  </beans>

以上就是關(guān)于Java培訓(xùn)之Spring4.3.14.RELEASE整合Hibernate5.2.10.Final的詳細(xì)介紹,最后想要了解更多關(guān)于JavaEE開發(fā)問題的小伙伴可以登錄扣丁學(xué)堂官網(wǎng)咨詢??鄱W(xué)堂是專業(yè)的JavaEE培訓(xùn)機構(gòu),不僅有專業(yè)的老師和與時俱進(jìn)的課程體系,還有大量的Java視頻教程供學(xué)員觀看學(xué)習(xí),想要學(xué)好JavaEE的小伙伴抓緊時間行動吧。Java技術(shù)交流群:670348138。




關(guān)注微信公眾號獲取更多學(xué)習(xí)資料



關(guān)注微信公眾號獲取更多學(xué)習(xí)資料



查看更多關(guān)于“Java開發(fā)資訊的相關(guān)文章>>


標(biāo)簽: Java視頻教程 Java培訓(xùn) Java開發(fā)工程師 Java在線視頻 Java在線學(xué)習(xí) Java在線教程

熱門專區(qū)

暫無熱門資訊

課程推薦

微信
微博
15311698296

全國免費咨詢熱線

郵箱:codingke@1000phone.com

官方群:148715490

北京千鋒互聯(lián)科技有限公司版權(quán)所有   北京市海淀區(qū)寶盛北里西區(qū)28號中關(guān)村智誠科創(chuàng)大廈4層
京ICP備2021002079號-2   Copyright ? 2017 - 2022
返回頂部 返回頂部