Native Hibernate与Hibernate JPA

本文作者:苏生米沿

本文地址:http://blog.csdn.net/sushengmiyan/article/details/50182005

翻译来源:http://stackoverflow.com/questions/20820880/hibernate-native-vs-hibernate-jpa

Hibernate 官方网站说,有native Hibernate API和 Hibernate 的JPA实现。在这两者之间有什么区别呢?优势劣势都是什么?

Hibernate website says there is a native Hibernate API as well as an implementation of JPA. What is the difference between the Native API and JPA implementation? Advantages, disadvantages?

在使用Spring MVC构建应用程序的时候,使用tomcat做为服务器,使用mysql作为持久化数据库,对spring来说,我是新手,并且没有使用过Hibernate,我的团队想通过使用ORM方案,并且比较来说,Hibernate比较流行。现在不确定,Hibernate 是如何工作的?或者,我该使用native Hibernate或者是hibernate的JPA实现?应用程序是数据驱动的,实体和报表展示的。

I am working on a Spring MVC application, using Tomcat as the container, and MySQL for persistence. I‘m newer to Spring and never used Hibernate. My team would like to use an ORM and Hibernate seems to be the most popular. We‘re not sure how Hibernate is going to workout or whether we should use native or JPA api. The application will be data driven, data entry, reporting, etc.

我知道,使用JPA的话,对于程序切换到另一个JPA实现会比较容易,尽管我不知道这样做是否是需要的。

I‘ve read that using JPA makes its easier to switch to another JPA implementation, although I don‘t know if that will be needed or not.

JPA是通过ORM访问关系数据库的一个标准,Hibernate是它的一个实现。当年想使用JPA的时候,你需要使用它的一个实现,hibernate是一个不错的选择,但是还有其它实现,比如EclipseLink。

JPA is a standard for accessing relational databases through an object oriented API. Hibernate is an implementation of this API. When you want to use JPA you need some vendor to implement it, Hibernate is a good choice but there are others like EclipseLink.

Hibernate 存在的时间比JPA要长久。陈旧的native API仍然存在,并且提供一些标准的JPA没有提供的功能,如果你需要使用这些的话你就选择native API,使用JPA的话,就是更多程序员了解它,并且也可以通过配置来使用这些特性。

Hibernate exists longer than JPA. The native, older API (which was a model for JPA) still exists, and sometimes it offers more possibilities than are exposed through JPA (e.g. orphan removal). If you need those you need to use the native API. Using JPA has other merits, most important (in my opinion) more developers that know it. And you still can use some Hibernate specifics through configuration.

大多数的使用native hibernate的体验都是陈旧的,像Hibernate 3,是JPA的发行前版本.如果你是刚开始,建议使用JPA开始,尽管native的也有很多好的使用原由。

Most tutorials that use Hibernate natively are quite old - as is Hibernate 3, a pre-JPA release. While there are good reasons to use it, they (IMO) typically don‘t apply to the general audience. So if you are just beginning to learn in this field I would suggest to start with JPA.

作为线下资源,这里并没有何时的话题,你需要借鉴官方文档作为一个开始,并且至少从Hibernate4开始体验。

As for recommendations on offsite resources: For good reasons they are not on topic here. But thecurrent official Hibernate documentation would be a good start, as would be to look for toturial for at least Hibernate 4.

时间: 2024-08-02 09:19:10

Native Hibernate与Hibernate JPA的相关文章

eclipse从数据库逆向生成Hibernate实体类(eclipse中反向生成hibernate实体类+jpa注释)

eclipse从数据库逆向生成Hibernate实体类 做项目必然要先进行数据库表设计,然后根据数据库设计建立实体类(VO),这是理所当然的,但是到公司里做项目后,让我认识到,没有说既进行完数据库设计后还要再"自己"建立一变VO.意思是,在项目设计时,要么根据需求分析建立实体类,由正向生成数据库表:要么就先进行数据库表设计,再逆向生成实体类.没有说进行完任意一方的设计后再去花时间去自己匹配建立另一方的设计. 原因是: 1. 1.5倍工作量,浪费时间.(时间对公司来说很重要) 2. 无法

Rhythmk 学习 Hibernate 03 - Hibernate 之 延时加载 以及 ID 生成策略

Hibernate 加载数据 有get,跟Load 1.懒加载: 使用session.load(type,id)获取对象,并不读取数据库,只有在使用返回对象值才正真去查询数据库. ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 @Test    public void  test1()    {        Session session = null;         try {             session = Hiber

Rhythmk 学习 Hibernate 05 - Hibernate 表间关系 [ManyToOne,OneToMany]

1.项目结构: 1.1.场景说明: 一个订单,包含多个产品 1.2.类文件: Order.java ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 package com.rhythmk.model; import java.util.Date; public

Rhythmk 学习 Hibernate 05 - Hibernate 表间关系 [One To One]

1.One To One 单相 背景: 古代一个老婆  只能关联一个老公 husband.java ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 package com.rhythmk.model; public class husband {          public Integer getHusbandId() {         return husbandId;     }     public void setHusba

Hibernate之Hibernate环境配置

Hibernate之Hibernate环境配置 一.Hibernate环境搭建的步骤 1.添加Hibernate && SQLServer 的Jar antlr-2.7.7.jar dom4j-1.6.1.jar hibernate-commons-annotations-4.0.5.Final.jar hibernate-core-4.3.11.Final.jar hibernate-jpa-2.1-api-1.0.0.Final.jar jandex-1.1.0.Final.jar j

Hibernate配置文件——hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <

Rhythmk 学习 Hibernate 02 - Hibernate 之 瞬时状态 离线状态 持久化状态 三状态

by:rhythmk.cnblogs.com 1.Hibernate 三种状态: 1.1.三种定义(个人理解,不一定准确):  瞬时状态(transient):    不被session接管,且不存在数据库中的对象的状态,类似于新New一个对象  离线状态 (detached):    数据库中存在而不被session接管  持久化状态(persistent): 对象被session管理且数据库中存在此对象 1.2. 状态之间转换关系图 2 .状态转换以及Hibernate数据库执行过程详解:

异常:org.hibernate.HibernateException: &#39;hibernate.dialect&#39; must be set when no Connection available

spring整合hibernate报了这样一个异常,一直以为是dialect参数的问题,最后发现原来是配数据源时,数据库的名字写错了....... 找了半天,重新写了配置文件没出问题,但就不知道这个文件哪里出问题了.配置文件里面这种细节一定要注意. 版权声明:本文为博主原创文章,未经博主允许不得转载. 异常:org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available

Rhythmk 学习 Hibernate 04 - Hibernate 辅助工具 之 JBoos Tool

1.安装JBoos Tool Help -> Install new Software 然后添加: http://download.jboss.org/jbosstools/updates/development http://download.jboss.org/jbosstools/updates/stable/ 稍等一刻,选择 Hibernate tool 下一步 ,完成后重启Eclipse即可. 2.项目配置文件生成: 2.1 新建一项目,项目右键生成相关配置 然后如图: 2.2 此处需