日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hibernate注解的测试

發布時間:2023/12/3 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hibernate注解的测试 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

注解用到的jar包:下載地址



/**

?? ? * ========================================================================
?? ? * 注解
?? ? * 步驟:
?? ? * 1.導入jar包
?? ? *??? (1)hibernate-annotations.jar
?? ? *??? (2)hibernate-commons-annotations.jar
?? ? *??? (3)ejb3-persistence.jar
?? ? * 2.使用注解配置持久化類級對象關聯關系
?? ? * 3.使用AnnotationConfiguration建立會話工廠
?? ? * sessionFaction=new AnnotationConfiguration().configure().buildSessionFactory();
?? ? * 4.在hibernate配置文件中(hibernate.cfg.xml)中生成持久化類
?? ? * <mapping class="持久化類完整限定名">
?? ? * ========================================================================
?? ? *

?? ? */

@Testpublic void test1(){//必須先在數據庫里面創建序列,名字是seq_emp_idSession session=new AnnotationConfiguration().configure().buildSessionFactory().openSession();Transaction tx=session.beginTransaction();Emp1 emp1=new Emp1();emp1.setEname("test2");emp1.setHiredate(new Date());session.save(emp1);tx.commit();}
//測試多對一的配置注解@Testpublic void test2(){Session session=new AnnotationConfiguration().configure().buildSessionFactory().openSession();Emp1 emp1=(Emp1) session.get(Emp1.class,7788);System.out.println(emp1.getEname()+","+emp1.getDept().getDname());}//級聯操作@Testpublic void test3(){Session session=new AnnotationConfiguration().configure().buildSessionFactory().openSession();Transaction tx=session.beginTransaction();Dept1 dept1=new Dept1(1,"產品部");Emp1 emp1=new Emp1();emp1.setEname("Villy");emp1.setHiredate(new Date());dept1.getEmps().add(emp1);emp1.setDept(dept1);session.save(dept1);tx.commit();}

總結

以上是生活随笔為你收集整理的hibernate注解的测试的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。