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

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

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

    隨筆-75  評論-193  文章-5  trackbacks-0

    EntityManager的定義

    The EntityManager manages the O/R mapping between a fixed set of entity classes and an underlying data source.
    It provides APIs for creating queries, finding objects, synchronizing objects, and inserting objects into the database.
    It also can provide caching and manage the interaction between an entity and transactional services in a Java EE environment such as JTA.
    The EntityManager is tightly integrated with Java EE and EJB but is not limited to this environment; it can be used in plain Java programs.

    An EntityManager maps a fixed set of classes to a particular database. This set of classes is called a persistence unit .

    In Java SE, entity managers are created using a javax.persistence.EntityManagerFactory
    Example:
        EntityManagerFactory factory = Persistence.createEntityManagerFactory("titan", map);
        EntityManager manager = factory.createEntityManager();
    在Java SE環境中,使用完EntityManagerFactory后,最好將其關閉,以釋放其占有的資源。

    和Java SE環境不一樣,在Java EE中,一個注入的EntityManagerFactory會被EJB容器自動關閉,實際上,如果你調用EntityManagerFactory的clost()方法時,會拋出IllegalStateException異常。

    public interface EntityManager {
       public void persist(Object entity);
       public <T> T find(Class <T> entityClass, Object primaryKey);
       public <T> T getReference(Class <T> entityClass, Object primaryKey);
       public <T> T merge(T entity);
       public void remove(Object entity);
       public void lock(Object entity, LockModeType lockMode);

       public void refresh(Object entity);
       public boolean contains(Object entity);
       public void clear( );

       public void joinTransaction( );
       public void flush( );
       public FlushModeType getFlushMode( );
       public void setFlushMode(FlushModeType type);

       public Query createQuery(String queryString);
       public Query createNamedQuery(String name);
       public Query createNativeQuery(String sqlString);
       public Query createNativeQuery(String sqlString, String resultSetMapping);
       public Query createNativeQuery(String sqlString, Class resultClass);

       public Object getDelegate( );

       public void close( );
       public boolean isOpen( );
    }

    Persistence context的定義

    A persistence context is a set of managed entity object instances.
    Persistence contexts are managed by an entity manager.

    There are two types of persistence contexts: transaction-scoped and extended persistence contexts.

    A persistence context can be created by calling the EntityManagerFactory.createEntityManager( ) method. The returned EntityManager instance represents an extended persistence context. If the EntityManagerFactory is JTA-enabled, then you have to explicitly enlist the EntityManager instance within a transaction by calling the EntityManager.joinTransaction( ) method. If you do not enlist the EntityManager within the JTA transaction, then changes you make to your entities are not synchronized with the database.

    FlushModeType的含義

    FlushModeType默認為AUTO模式,當為AUTO時,在一個查詢被執行前,會自動將變化提交到數據庫中,即調用flush()方法。但是調用find()或getreference()方法時,并不會執行自動提交。當為COMMIT模式時,僅僅在事務提交時,會將變化提交到數據庫中。

    EJB3中的實體注解規范參見如下鏈接
    http://wiki.redsaga.com/confluence/display/HART/Home

    posted on 2007-05-07 23:42 The Matrix 閱讀(602) 評論(0)  編輯  收藏 所屬分類: EJB3

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 麻豆狠色伊人亚洲综合网站 | 一级特黄特色的免费大片视频| 四虎精品成人免费视频| 日韩免费电影网站| 日韩免费观看一级毛片看看 | 亚洲2022国产成人精品无码区| 国产亚洲精品成人AA片| 成人自慰女黄网站免费大全 | 四虎永久成人免费| 亚洲网站视频在线观看| 亚洲丰满熟女一区二区哦| 亚洲精品免费视频| 国产偷窥女洗浴在线观看亚洲| 亚洲一级毛片中文字幕| 国产免费无码一区二区| 亚洲午夜福利精品无码| 亚洲国产成人精品无码区花野真一 | 免费看少妇作爱视频| 亚洲精品私拍国产福利在线| 人人鲁免费播放视频人人香蕉| 亚洲精品第一国产综合境外资源| 亚洲乱码一二三四区麻豆| 男女作爱在线播放免费网站| 亚洲毛片在线观看| 永久免费AV无码国产网站| 亚洲黄色高清视频| 丁香花在线观看免费观看| 亚洲日本在线免费观看| 野花香高清视频在线观看免费| 亚洲国产精品一区二区久久| 在线观看成人免费视频不卡| 久久亚洲中文字幕精品有坂深雪| 99久久精品毛片免费播放| 亚洲?v女人的天堂在线观看| 大桥未久亚洲无av码在线| 麻豆国产VA免费精品高清在线 | 中国好声音第二季免费播放| 亚洲欧洲国产精品你懂的| 毛片在线看免费版| 2022国内精品免费福利视频| 亚洲成人高清在线|