简体   繁体   中英

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?

The project's 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).

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.

It's similar to 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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