<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    千里冰封
    JAVA 濃香四溢
    posts - 151,comments - 2801,trackbacks - 0
    以前使用JPA的實(shí)現(xiàn)是toplink,現(xiàn)在改為hibernate,所以要修改persistence.xml文件,兩者的配置有一些不一樣,并且在EE環(huán)境下面和SE的環(huán)境下面也有不一樣,還有一點(diǎn),那就是當(dāng)persistence.xml里面有些格式出錯(cuò)的時(shí)候,雖然出錯(cuò)的不是我們需要的那個(gè)單元,但也會(huì)使得整個(gè)persistence.xml報(bào)廢。

    下面帖的是在SE的環(huán)境下面使用toplink和hibernate的實(shí)現(xiàn),兩者都寫在同一個(gè)persistence.xml里面。這樣切換起來也方便一些。

    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="1.0" 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">
      
    <persistence-unit name="TestSSH2PU" transaction-type="RESOURCE_LOCAL">
        
    <provider>oracle.toplink.essentials.PersistenceProvider</provider>
        
    <class>com.hadeslee.jpaentity.Department</class>
        
    <class>com.hadeslee.jpaentity.Person</class>
        
    <properties>
          
    <property name="toplink.jdbc.user" value="sa"/>
          
    <property name="toplink.jdbc.password" value="hadeslee"/>
          
    <property name="toplink.jdbc.url" value="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testSSH"/>
          
    <property name="toplink.jdbc.driver" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
          
    <property name="toplink.ddl-generation" value="create-tables"/>
        
    </properties>
      
    </persistence-unit>
      
    <persistence-unit name="TestSSH1PU2" transaction-type="RESOURCE_LOCAL">
        
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
        
    <class>com.hadeslee.jpaentity.Department</class>
        
    <class>com.hadeslee.jpaentity.Person</class>
       <properties>
            
    <property name="hibernate.connection.driver_class" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
            
    <property name="hibernate.connection.url" value="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testSSH"></property>
            
    <property name="hibernate.connection.username" value="sa"></property>
            
    <property name="hibernate.connection.password" value="hadeslee"></property>
            
    <property name="hibernate.show_sql" value="true"></property>
            
    <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"></property>
            
    <property name="hibernate.current_session_context_class" value="thread"></property>
        
    </properties>
      
    </persistence-unit>
    </persistence>


    在SE的環(huán)境下面,是不能使用容器的JTA的數(shù)據(jù)源的。并且不能使用
    <exclude-unlisted-classes>true</exclude-unlisted-classes>這個(gè)屬性。
    本文重點(diǎn)是記錄下兩個(gè)常用的JPA的實(shí)現(xiàn)的配置。目前是在SE環(huán)境下的配置。EE環(huán)境下面的配置如下:
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="1.0" 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">
      
    <persistence-unit name="unit_mssql" transaction-type="JTA">
        
    <provider>oracle.toplink.essentials.PersistenceProvider</provider>
        
    <jta-data-source>MobileOAMSSQL</jta-data-source>
        
    <properties>
          
    <property name="toplink.ddl-generation" value="create-tables"/>
          
    <property name="toplink.logging.level" value="FINE"/>
        
    </properties>
      
    </persistence-unit>
     
    <persistence-unit name="MyApp-ejbPU2" transaction-type="JTA">
        
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
        
    <jta-data-source>MobileOAMYSQL</jta-data-source>
        
    <properties>
          
    <property name="hibernate.hbm2ddl.auto" value="update"/>
          
    <property name="hibernate.show_sql" value="true"/>
        
    </properties>
      
    </persistence-unit>
    </persistence>

    在EE環(huán)境下面使用JPA配置就簡單了許多,首先他可以把當(dāng)前模塊的CLASS文件都包括進(jìn)來,不用手工指定。并且也少了很多有關(guān)于數(shù)據(jù)庫連接的操作,因?yàn)檫@個(gè)時(shí)候都是從容器里面去取數(shù)據(jù)源的。并且此時(shí)的事務(wù)是由容器去管理的,也就是使用JTA,不再是RESOURCE_LOCAL了。這樣在代碼里面就不用em.getTransaction().begin();和em.getTransaction().commit()了,并且可以使用注入功能,把EntityManager注入到使用它的地方了。






    盡管千里冰封
    依然擁有晴空

    你我共同品味JAVA的濃香.
    posted on 2008-10-19 18:38 千里冰封 閱讀(5072) 評論(3)  編輯  收藏 所屬分類: JAVAEE

    FeedBack:
    # re: 使用JPA的不同實(shí)現(xiàn)的配置[未登錄]
    2008-10-19 22:56 | ytl
    好久沒看到你寫文章啦。。  回復(fù)  更多評論
      
    # re: 使用JPA的不同實(shí)現(xiàn)的配置
    2008-10-21 09:40 | attend
    多謝分享.  回復(fù)  更多評論
      
    # re: 使用JPA的不同實(shí)現(xiàn)的配置[未登錄]
    2009-09-22 01:14 | CC
    除了persistence.xml還要配置其它的地方嗎?
    想在tomcat中使用它  回復(fù)  更多評論
      
    主站蜘蛛池模板: 亚洲色精品88色婷婷七月丁香| 国产精品免费一级在线观看| 亚洲人成无码网站| 日韩久久无码免费毛片软件| 国产免费人成视频在线观看 | 好看的亚洲黄色经典| 伊人免费在线观看高清版| 中文字幕亚洲激情| 最近免费中文字幕中文高清| 亚洲一区二区三区偷拍女厕| 波多野结衣免费一区视频| 亚洲AV第一页国产精品| 5g影院5g天天爽永久免费影院 | 我要看WWW免费看插插视频| 亚洲香蕉久久一区二区三区四区| 国语成本人片免费av无码| 亚洲中文精品久久久久久不卡| 日韩免费观看视频| 国产精品免费一区二区三区| 亚洲AV无码欧洲AV无码网站| 在线人成精品免费视频| 亚洲欧洲另类春色校园网站| 永久久久免费浮力影院| 无码 免费 国产在线观看91| 国产亚洲精品a在线观看app| 美女内射毛片在线看免费人动物| 亚洲高清有码中文字| 亚洲国产人成精品| 男女作爱在线播放免费网站| 亚洲免费闲人蜜桃| 亚洲国产成人久久综合区| 国产精品免费观看调教网| 色天使亚洲综合在线观看| 亚洲色偷偷综合亚洲AV伊人| 一级毛片免费视频| 久久精品国产亚洲av天美18| 亚洲精品成人无限看| 成人A级毛片免费观看AV网站| 国产黄在线观看免费观看不卡| 亚洲性一级理论片在线观看| 五月婷婷亚洲综合|