步骤如下。

成都创新互联是专业的卢龙网站建设公司,卢龙接单;提供成都网站设计、做网站,网页设计,网站设计,建网站,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配置文件:
【编辑推荐】
                网站题目:利用Netbeans5.5生成功能来开发Hibernate3
                
                转载来于:http://www.csdahua.cn/qtweb/news24/241224.html
            
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网