这篇文章主要讲解了“如何利用Netbeans5.5生成功能来开发Hibernate3”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“如何利用Netbeans5.5生成功能来开发Hibernate3”吧!

我们提供的服务有:成都网站制作、成都网站设计、外贸营销网站建设、微信公众号开发、网站优化、网站认证、孙吴ssl等。为近1000家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的孙吴网站制作公司
步骤如下。
需要安装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配置文件:
- 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">MSSQL2000POOLproperty> 
- name="hibernate.proxool.xml">Proxool.xmlproperty> 
- name="dialect"> 
- org.hibernate.dialect.SQLServerDialect 
- property> 
- name="show_sql">falseproperty> 
- name="hbm2ddl.auto">createproperty> 
- session-factory> 
- hibernate-configuration> 
- 连接池配置文件: 
- version="1.0" encoding="UTF-8"?> 
- MSSQL2000POOLalias> 
- jdbc:jtds:sqlserver://localhost:1433/hibernate3driver-url> 
- net.sourceforge.jtds.jdbc.Driverdriver-class> 
- name="user" value="sa" /> 
- name="password" value="sa" /> 
- driver-properties> 
- 10maximum-connection-count> 
- select CURRENT_DATE 
- house-keeping-test-sql> 
- proxool> 
- something-else-entirely> 
感谢各位的阅读,以上就是“如何利用Netbeans5.5生成功能来开发Hibernate3”的内容了,经过本文的学习后,相信大家对如何利用Netbeans5.5生成功能来开发Hibernate3这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!
新闻名称:如何利用Netbeans5.5生成功能来开发Hibernate3
标题路径:http://www.cqwzjz.cn/article/gpicid.html

 建站
建站
 咨询
咨询 售后
售后
 建站咨询
建站咨询 
 