溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

如何利用Netbeans5.5生成功能來(lái)開(kāi)發(fā)Hibernate3

發(fā)布時(shí)間:2021-07-13 15:57:32 來(lái)源:億速云 閱讀:152 作者:chen 欄目:編程語(yǔ)言

這篇文章主要講解了“如何利用Netbeans5.5生成功能來(lái)開(kāi)發(fā)Hibernate3”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“如何利用Netbeans5.5生成功能來(lái)開(kāi)發(fā)Hibernate3”吧!

步驟如下。

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

1.使用Netbeans5.5生成EntityClass

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

3.使用AnnotationConfiguration

注)推薦proxool-0.9.0RC3

import org.hibernate.Session;  import org.hibernate.SessionFactory;  import org.hibernate.Transaction;  import org.hibernate.cfg.AnnotationConfiguration;  import org.hibernate.cfg.Environment;   import com.hb.pack_01.model.P01_Customer;    public class BusinessService ...{       public static SessionFactory sessionFactory;       static ...{          try ...{              AnnotationConfiguration cfg = new AnnotationConfiguration();              cfg.configure("hibernate.cfg.xml");              cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop");              cfg.addPackage("com.hb.pack_01.model");              cfg.addAnnotatedClass(P01_Customer.class );              sessionFactory = cfg.buildSessionFactory();          } catch (Exception e) ...{              e.printStackTrace();          }      }            public void saveCustomer(P01_Customer customer) throws Exception ...{          Session session = sessionFactory.openSession();          Transaction tx = null;          try ...{              tx = session.beginTransaction();              session.save(customer);              tx.commit();          } catch (Exception e) ...{              if (tx != null) ...{                  tx.rollback();              }              throw e;          } finally ...{              session.close();          }      }            public void test() throws Exception ...{           P01_Customer customer = new P01_Customer();          customer.setName("Laosan Zhang");          customer.setSex(''M'');          customer.setCustomerDescription("A good citizen!");          saveCustomer(customer);      }            public static void main(String[] args) throws Exception ...{                    new BusinessService().test();          sessionFactory.close();      }  }

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. <hibernate-configuration> 

  6.     <session-factory> 

  7.          

  8.         <property name="hibernate.connection.provider_class"> 

  9.             org.hibernate.connection.ProxoolConnectionProvider  

  10.         property> 

  11.         <property name="hibernate.proxool.pool_alias">MSSQL2000POOLproperty> 

  12.         <property name="hibernate.proxool.xml">Proxool.xmlproperty> 

  13.          

  14.         <property name="dialect"> 

  15.             org.hibernate.dialect.SQLServerDialect  

  16.         property> 

  17.          

  18.         <property name="show_sql">falseproperty> 

  19.          

  20.         <property name="hbm2ddl.auto">createproperty> 

  21.  

  22.     session-factory> 

  23. hibernate-configuration> 

  24.  

  25.  連接池配置文件:  

  26.  

  27.  

  28.  

  29. <?xml version="1.0" encoding="UTF-8"?> 

  30.  

  31. <something-else-entirely> 

  32.     <proxool> 

  33.         <alias>MSSQL2000POOLalias> 

  34.         <driver-url>jdbc:jtds:sqlserver://localhost:1433/hibernate3driver-url> 

  35.         <driver-class>net.sourceforge.jtds.jdbc.Driverdriver-class> 

  36.         <driver-properties> 

  37.             <property name="user" value="sa" /> 

  38.             <property name="password" value="sa" /> 

  39.         driver-properties> 

  40.         <maximum-connection-count>10maximum-connection-count> 

  41.         <house-keeping-test-sql> 

  42.             select CURRENT_DATE  

  43.         house-keeping-test-sql> 

  44.     proxool> 

  45. something-else-entirely> 

感謝各位的閱讀,以上就是“如何利用Netbeans5.5生成功能來(lái)開(kāi)發(fā)Hibernate3”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)如何利用Netbeans5.5生成功能來(lái)開(kāi)發(fā)Hibernate3這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI