随笔 - 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 河马虎 阅读(539) 评论(0)  编辑  收藏 所属分类: WebSphere


只有注册用户登录后才能发表评论。


网站导航: