hibernate jpa
来源:互联网 发布:信访网络舆情应急预案 编辑:程序博客网 时间:2024/06/06 19:24
Hibernate JPA ;
JPA首先需要一个配置文件,在原生的hibernate 中我们需要的是一个hibernate.cfg.xml 来配置连接数据库的相关信息,但在JPA中我们需要的是persistence.xml 在这里配置数据库的相关信息, 然后利用这些信息来创建一个EntityManagerFactory 如:entityManagerFactory = Persistence.createEntityManagerFactory( "org.hibernate.tutorial.jpa" )
然后利用entityManagerFactory 创建一个entityManager, 该对象就相当于在原生的hibernate中的session一样,用来操作数据库的代码如下
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
entityManager.persist( new Event( "Our very first event!", new Date() ) );
entityManager.persist( new Event( "A follow up event", new Date() ) );
entityManager.getTransaction().commit();
entityManager.close();
可以看到其操作数据库的代码和原生的session是一样的
Session session = sessionFactory.openSession();
session.beginTransaction();
session.save( new Event( "Our very first event!", new Date() ) );
session.save( new Event( "A follow up event", new Date() ) );
session.getTransaction().commit();
session.close();
Session session = sessionFactory.openSession();
session.beginTransaction();
session.save( new Event( "Our very first event!", new Date() ) );
session.save( new Event( "A follow up event", new Date() ) );
session.getTransaction().commit();
session.close();
- Hibernate+JPA
- Hibernate+JPA
- Hibernate JPA
- hibernate jpa
- hibernate jpa
- hibernate jpa
- Hibernate JPA
- [Hibernate] JPA Hibernate 3.5
- JPA 和hibernate-jpa-api
- SPRING JPA 与 Hibernate JPA
- Native Hibernate与Hibernate JPA
- Native Hibernate与Hibernate JPA
- 原生Hibernate和Jpa Hibernate
- 学习Hibernate JPA
- JPA & Hibernate 注解
- struts2+spring+jpa(hibernate)
- hibernate,jpa锁机制
- JPA与Hibernate
- C++ Refactoring in Visual Studio 2015
- linux运维初涉及
- 不用加号的数字运算
- ViewParger的使用
- java中volatile关键字的含义
- hibernate jpa
- /usr/bin/ld: cannot find -lcrypto 错误的解决方法
- Android Zxing 扫描器 扫描框、扫描线定制样式
- inux系统调用fcnt()l函数详解
- android studio 快捷键
- linux查看系统编码和修改系统编码的方法
- 提高项目27.2解密
- 思考:你的互联网+项目为何敏捷不起来?三、流程环节之间的依赖
- LoRaWAN 规范 1.0 (章节5)