隨筆 - 34, 文章 - 1, 評(píng)論 - 2, 引用 - 0
          數(shù)據(jù)加載中……

          hibernate use Websphere datasource

          reference  url:
              http://www.ibm.com/developerworks/websphere/techjournal/0609_alcott/0609_alcott.html

          when  webSphere  application server  startup,  hibernate uses  WebSphere datasource.
          step by  step:

               1  coding  statup  constom service

                 import javax.management.Notification;
                import javax.management.NotificationFilterSupport;
                import javax.management.NotificationListener;
                import javax.management.ObjectName;
                
                public class WebsphereStartup implements CustomService,NotificationListener {
                  public void initialize(Properties arg0) throws Exception {    
                     NotificationFilterSupport filter = new NotificationFilterSupport();   
                     filter.enableType(NotificationConstants.TYPE_J2EE_STATE_RUNNING);
                     ObjectName target = new ObjectName("WebSphere:*,type=Server");   
                     AdminServiceFactory.getAdminService().addNotificationListenerExtended(
                      target,
                      this,
                      filter,
                      null);
                 } 
                 public void shutdown() throws Exception {
                   // When  was  shutdown,  this  method  is  executed
                  
                 } 
                 public void handleNotification(Notification notification, Object handback) {
                   //  write  init  code  here
                   init();
                 }
                }

               2  modify    hibernate config file  hibernate.cfg.xml

                               <property name="hibernate.connection.datasource">data  source  jndi</property>
                              <property name="hibernate.connection.username">name</property>
                               <property name="hibernate.connection.password">password</property>
                               <property name="hibernate.session_factory_name">HibernateSessionFactory</property>  
                                <property name="connection.autocommit">false</property>
                              <property name="net.sf.hibernate.transaction.JTATransactionFactory">net.sf.hibernate.transaction.WebSphereTransactionManagerLookup</property>
                                <property name="show_sql">false</property>
                               <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>

                        注意:如果是非事務(wù)性數(shù)據(jù)源  那么在hibernate.cfg.xml  必須設(shè)置 <property name="connection.autocommit">false</property>
                                為false
                                     
               3   create  datasource   jndi  on  was
                       如果是非事務(wù)性數(shù)據(jù)源,在建立數(shù)據(jù)源時(shí),也要設(shè)置為非事務(wù)性數(shù)據(jù)源。
                4    config  custom service  bean  on Websphere
                       was console >servers> application server > server1>manage>custom service >new
                 5 start Server

          posted on 2009-12-18 09:19 河馬虎 閱讀(556) 評(píng)論(0)  編輯  收藏 所屬分類: WebSphere

          主站蜘蛛池模板: 阿拉尔市| 临汾市| 保山市| 南平市| 阜南县| 临夏县| 汨罗市| 理塘县| 左贡县| 东乌| 甘孜| 新乐市| 介休市| 克拉玛依市| 黄石市| 淅川县| 宁波市| 镶黄旗| 建水县| 福建省| 饶阳县| 玉树县| 宁陵县| 丰宁| 莱芜市| 任丘市| 乐昌市| 兴城市| 永川市| 通河县| 遂宁市| 乌兰县| 平湖市| 汉川市| 兴仁县| 突泉县| 通山县| 商城县| 池州市| 嵊州市| 漠河县|