隨筆 - 34, 文章 - 1, 評論 - 2, 引用 - 0
          數據加載中……

          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>

                        注意:如果是非事務性數據源  那么在hibernate.cfg.xml  必須設置 <property name="connection.autocommit">false</property>
                                為false
                                     
               3   create  datasource   jndi  on  was
                       如果是非事務性數據源,在建立數據源時,也要設置為非事務性數據源。
                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 河馬虎 閱讀(552) 評論(0)  編輯  收藏 所屬分類: WebSphere

          主站蜘蛛池模板: 镶黄旗| 资源县| 莲花县| 曲靖市| 颍上县| 华池县| 姜堰市| 荔浦县| 通海县| 西乌| 调兵山市| 临武县| 贺兰县| 涞源县| 曲周县| 永康市| 启东市| 顺平县| 闸北区| 铁岭市| 青浦区| 连山| 西畴县| 长沙市| 汉沽区| 延川县| 固镇县| 三台县| 无锡市| 九龙坡区| 阿鲁科尔沁旗| 岢岚县| 弥勒县| 敖汉旗| 通城县| 定结县| 丁青县| 昂仁县| 南川市| 马山县| 绥宁县|