利用Netbeans5.5生成功能来开发Hibernate3
步骤如下。

成都创新互联是专业的卢龙网站建设公司,卢龙接单;提供成都网站设计、做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行卢龙网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
需要安装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发布,支持Ruby、移动开发和集成的剖析器
- NetBeans 6.0预览版发布 Sun再引惊呼
- NetBeans成为Ruby开发者的新伙伴(3)
- 八大技术牛人点评NetBeans 6.5
网页名称:利用Netbeans5.5生成功能来开发Hibernate3
网站地址:http://www.jxjierui.cn/article/djhdjpe.html


咨询
建站咨询
