日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
利用Netbeans5.5生成功能來開發(fā)Hibernate3

步驟如下。

成都創(chuàng)新互聯(lián)是專業(yè)的盧龍網(wǎng)站建設(shè)公司,盧龍接單;提供成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站,網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行盧龍網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!

需要安裝Netbeans5.5或以上版本。

1.使用Netbeans5.5生成EntityClass

2.給EntityClass的id字段注明生成方式,如:@GeneratedValue

3.使用AnnotationConfiguration

注)推薦proxool-0.9.0RC3

 
 
 
  1. import org.hibernate.Session;  
  2. import org.hibernate.SessionFactory;  
  3. import org.hibernate.Transaction;  
  4. import org.hibernate.cfg.AnnotationConfiguration;  
  5. import org.hibernate.cfg.Environment;  
  6.  
  7. import com.hb.pack_01.model.P01_Customer;  
  8.  
  9.  
  10. public class BusinessService ...{  
  11.  
  12.     public static SessionFactory sessionFactory;  
  13.  
  14.     static ...{  
  15.         try ...{  
  16.             AnnotationConfiguration cfg = new AnnotationConfiguration();  
  17.             cfg.configure("hibernate.cfg.xml");  
  18.             cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop");  
  19.             cfg.addPackage("com.hb.pack_01.model");  
  20.             cfg.addAnnotatedClass(P01_Customer.class );  
  21.             sessionFactory = cfg.buildSessionFactory();  
  22.         } catch (Exception e) ...{  
  23.             e.printStackTrace();  
  24.         }  
  25.     }  
  26.       
  27.     public void saveCustomer(P01_Customer customer) throws Exception ...{  
  28.         Session session = sessionFactory.openSession();  
  29.         Transaction tx = null;  
  30.         try ...{  
  31.             tx = session.beginTransaction();  
  32.             session.save(customer);  
  33.             tx.commit();  
  34.         } catch (Exception e) ...{  
  35.             if (tx != null) ...{  
  36.                 tx.rollback();  
  37.             }  
  38.             throw e;  
  39.         } finally ...{  
  40.             session.close();  
  41.         }  
  42.     }  
  43.       
  44.     public void test() throws Exception ...{  
  45.  
  46.         P01_Customer customer = new P01_Customer();  
  47.         customer.setName("Laosan Zhang");  
  48.         customer.setSex(''M'');  
  49.         customer.setCustomerDescription("A good citizen!");  
  50.         saveCustomer(customer);  
  51.     }  
  52.       
  53.     public static void main(String[] args) throws Exception ...{  
  54.           
  55.         new BusinessService().test();  
  56.         sessionFactory.close();  
  57.     }  
  58. }  

 Hibernate配置文件:

  1. xml version=''1.0'' encoding=''utf-8''?> 
  2.         "-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
  3.         "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 
  4.  
  5.  
  6.      
  7.           
  8.          name="hibernate.connection.provider_class"> 
  9.             org.hibernate.connection.ProxoolConnectionProvider  
  10.          property> 
  11.          name="hibernate.proxool.pool_alias">MSSQL2000POOL property> 
  12.          name="hibernate.proxool.xml">Proxool.xml property> 
  13.           
  14.          name="dialect"> 
  15.             org.hibernate.dialect.SQLServerDialect  
  16.          property> 
  17.           
  18.          name="show_sql">false property> 
  19.           
  20.          name="hbm2ddl.auto">create property> 
  21.  
  22.      session-factory> 
  23. hibernate-configuration> 
  24.  
  25.  連接池配置文件:  
  26.  
  27.  
  28.  
  29. xml version="1.0" encoding="UTF-8"?> 
  30.  
  31.  
  32.      
  33.         MSSQL2000POOL alias> 
  34.         jdbc:jtds:sqlserver://localhost:1433/hibernate3 driver-url> 
  35.         net.sourceforge.jtds.jdbc.Driver driver-class> 
  36.          
  37.              name="user" value="sa" /> 
  38.              name="password" value="sa" /> 
  39.          driver-properties> 
  40.         10 maximum-connection-count> 
  41.          
  42.             select CURRENT_DATE  
  43.          house-keeping-test-sql> 
  44.      proxool> 
  45. something-else-entirely> 

【編輯推薦】

  1. NetBeans 6.0模塊快速入門教程
  2. Netbeans 6.0發(fā)布,支持Ruby、移動(dòng)開發(fā)和集成的剖析器
  3. NetBeans 6.0預(yù)覽版發(fā)布 Sun再引驚呼
  4. NetBeans成為Ruby開發(fā)者的新伙伴(3)
  5. 八大技術(shù)牛人點(diǎn)評NetBeans 6.5

標(biāo)題名稱:利用Netbeans5.5生成功能來開發(fā)Hibernate3
文章轉(zhuǎn)載:http://www.dlmjj.cn/article/djhdjpe.html