新聞中心
這里有您想知道的互聯(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
- 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配置文件:
- xml version=''1.0'' encoding=''utf-8''?>
- "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
-
-
name="hibernate.connection.provider_class"> - org.hibernate.connection.ProxoolConnectionProvider
- property>
-
name="hibernate.proxool.pool_alias">MSSQL2000POOL property> -
name="hibernate.proxool.xml">Proxool.xml property> -
name="dialect"> - org.hibernate.dialect.SQLServerDialect
- property>
-
name="show_sql">false property> -
name="hbm2ddl.auto">create property> - session-factory>
- hibernate-configuration>
- 連接池配置文件:
- xml version="1.0" encoding="UTF-8"?>
-
-
MSSQL2000POOL alias> -
jdbc:jtds:sqlserver://localhost:1433/hibernate3 driver-url> -
net.sourceforge.jtds.jdbc.Driver driver-class> -
-
name="user" value="sa" /> -
name="password" value="sa" /> - driver-properties>
-
10 maximum-connection-count> -
- select CURRENT_DATE
- house-keeping-test-sql>
- proxool>
- something-else-entirely>
【編輯推薦】
- NetBeans 6.0模塊快速入門教程
- Netbeans 6.0發(fā)布,支持Ruby、移動(dòng)開發(fā)和集成的剖析器
- NetBeans 6.0預(yù)覽版發(fā)布 Sun再引驚呼
- NetBeans成為Ruby開發(fā)者的新伙伴(3)
- 八大技術(shù)牛人點(diǎn)評NetBeans 6.5
標(biāo)題名稱:利用Netbeans5.5生成功能來開發(fā)Hibernate3
文章轉(zhuǎn)載:http://www.dlmjj.cn/article/djhdjpe.html


咨詢
建站咨詢
