简体   繁体   English

在没有JPA规范的情况下休眠如何工作

[英]how hibernate can work without JPA specification

I was working on project which did not have JPA , however it uses Hibernate could anyone please explain how? 我当时在从事没有JPA项目,但是它使用的是Hibernate ,谁能解释一下吗?

The project's pom.xml : 项目的pom.xml

   <dependency>
       <groupId>org.hibernate</groupId>
       <artifactId>hibernate-core</artifactId>
       <version>${hibernate.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>${hibernate.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.1.3.Final</version>
    </dependency>

Hibernate is a JPA implementation, meaning that when you're using JPA you could be using Hibernate, EclipseLink or any of the other implementations but you would code according to JPA specs, ie using javax.persistence.* interfaces, usually avoiding using implementation specific features (although that's still possible). Hibernate是一个JPA实现,这意味着当您使用JPA时,您可以使用Hibernate,EclipseLink或任何其他实现,但是您将根据JPA规范进行编码,即使用javax.persistence.*接口,通常避免使用特定于实现的代码功能(尽管仍然可行)。

If you're coding directly with Hibernate, you would use only its specific classes (ie org.hibernate.* ) and ways, and have no reference to javax.persistence anywhere. 如果直接使用Hibernate进行编码,则将仅使用其特定的类(即org.hibernate.* )和方式,而在任何地方都没有引用javax.persistence

It's similar to JDBC . 它类似于JDBC You could write code that uses driver specific classes (and sometimes, but not often, there are valid reasons why you need to), but there are classes which implement the JDBC interfaces ( Connection , ResultSet , Statement etc.) so you can write regular JDBC code without having to learn things again when you switch to a different database. 您可以编写使用特定于驱动程序的类的代码(有时,但有一些并非经常,有这样做的正当理由),但是有些类实现了JDBC接口( ConnectionResultSetStatement等),因此您可以编写常规代码切换到其他数据库时无需再次学习的JDBC代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM