自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Hibernate會話工廠簡介

開發(fā) 后端
這里介紹獲取Hibernate會話工廠,盡管無需驚天的修改,但這一工作與使用 Hibernate Annotations有所不同。您需要使用AnnotationConfiguration 類來建立會話工廠.

本文向大家介紹Hibernate會話工廠,可能好多人還不了解Hibernate會話工廠,沒有關(guān)系,看完本文你肯定有不少收獲,希望本文能教會你更多東西。

安裝Hibernate Annotation

要使用 Hibernate Annotation,您至少需要具備 Hibernate 3.2和Java 5。可以從 Hibernate 站點(diǎn) 下載 Hibernate 3.2 和 Hibernate Annotation庫。除了標(biāo)準(zhǔn)的 Hibernate JAR 和依賴項(xiàng)之外,您還需要 Hibernate Annotations .jar 文件(hibernate-annotations.jar)、Java 持久性 API (lib/ejb3-persistence.jar)。如果您正在使用 Maven,只需要向 POM 文件添加相應(yīng)的依賴項(xiàng)即可,如下所示:

  1. ...  
  2. <dependency> 
  3. <groupId>org.hibernate</groupId> 
  4. <artifactId>hibernate</artifactId> 
  5. <version>3.2.1.ga</version> 
  6. </dependency> 
  7. <dependency> 
  8. <groupId>org.hibernate</groupId> 
  9. <artifactId>hibernate-annotations</artifactId> 
  10. <version>3.2.0.ga</version> 
  11. </dependency> 
  12. <dependency> 
  13. <groupId>javax.persistence</groupId> 
  14. <artifactId>persistence-api</artifactId> 
  15. <version>1.0</version> 
  16. </dependency> 
  17. ...  

下一步就是獲取Hibernate會話工廠。盡管無需驚天的修改,但這一工作與使用 Hibernate Annotations有所不同。您需要使用AnnotationConfiguration 類來建立會話工廠:

  1. sessionFactory = new AnnotationConfiguration().buildSessionFactory(); 

盡管通常使用 <mapping> 元素來聲明持久性類,您還是需要在 Hibernate 配置文件(通常是 hibernate.cfg.xml)中聲明持久性類:

  1. <!DOCTYPE hibernate-configuration PUBLIC 
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"
    > 
  2. <hibernate-configuration> 
  3. <session-factory> 
  4. <mapping class="com.onjava.modelplanes.domain.PlaneType"/> 
  5. <mapping class="com.onjava.modelplanes.domain.ModelPlane"/> 
  6. </session-factory> 
  7. </hibernate-configuration> 

近期的許多 Java 項(xiàng)目都使用了輕量級的應(yīng)用框架,例如 Spring。如果您正在使用 Spring 框架,可以使用 AnnotationSessionFactoryBean 類輕松建立一個(gè)基于注釋的Hibernate會話工廠,如下所示:

  1. <!-- Hibernate session factory --> 
  2. <bean id="sessionFactory"   
  3. class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
  4. <property name="dataSource"> 
  5. <ref bean="dataSource"/> 
  6. </property> 
  7. <property name="hibernateProperties"> 
  8. <props> 
  9. <prop key="hibernate.dialect">org.hibernate.dialect.DerbyDialect</prop> 
  10. <prop key="hibernate.hbm2ddl.auto">create</prop> 
  11. ...  
  12. </props> 
  13. </property> 
  14. <property name="annotatedClasses"> 
  15. <list> 
  16. <value>com.onjava.modelplanes.domain.PlaneType</value> 
  17. <value>com.onjava.modelplanes.domain.ModelPlane</value> 
  18. ...  
  19. </list> 
  20. </property> 
  21. </bean> 

【編輯推薦】

  1. 獲取Hibernate關(guān)聯(lián)關(guān)系的方法
  2. 詳細(xì)講述Hibernate綁定JNDI
  3. Hibernate Customer客戶對象
  4. 講述Hibernate Session緩存
  5. 簡單分析Hibernate讀取Clob
責(zé)任編輯:佚名 來源: 博客園
相關(guān)推薦

2009-09-24 16:53:47

Hibernate A

2009-09-21 13:19:06

Hibernate s

2009-09-29 17:00:08

Hibernate c

2009-06-30 14:08:00

Hibernate緩存

2009-06-02 17:18:10

hibernate框架簡介

2009-09-24 08:48:54

Hibernate技術(shù)

2009-06-26 16:19:32

Hibernate實(shí)現(xiàn)

2009-06-12 14:40:38

Hibernate AHibernate接口

2010-07-26 13:03:23

Telnet會話

2010-09-07 15:56:37

PPPoE會話

2012-02-08 14:24:35

HibernateJava

2021-03-06 22:50:58

設(shè)計(jì)模式抽象

2011-11-17 16:03:05

Java工廠模式Clojure

2009-06-18 10:41:18

Hibernate3.Hibernate3.

2009-06-18 11:43:40

Hibernate uHibernate s

2009-09-28 10:39:01

Hibernate基礎(chǔ)

2009-06-02 14:46:26

Hibernate關(guān)系映射教程

2024-03-06 13:19:19

工廠模式Python函數(shù)

2012-02-08 11:15:38

HibernateJava

2009-09-27 16:21:22

Hibernate C
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號