D
D
Denis Kuznetsov2019-06-21 20:05:53
Java
Denis Kuznetsov, 2019-06-21 20:05:53

How does Hibernate differ from spring Data and, in principle, database tools?

Hello, I was doing a project and it seemed to me that I used Spring Data for it, here is part of my pom

<dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
...

it seems that spring data is connected
, but in the properties I have the installation, as I understand it, for hibernate
# ===============================
# JPA / HIBERNATE
# ===============================

spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect

# Fix Postgres JPA Error:
# Method org.postgresql.jdbc.PgConnection.createClob() is not yet implemented.
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false

so my question is what did I use and how does one differ from the other
+ when starting the project, after spring boot launched autoconfiguration and started looking for beans (that is, @springBootApplication worked, which includes 3 annotations @SpringBootConfiguration, @EnableAutoConfiguration and @ ComponentScan , imported all the necessary configs, tried to muddle the beans, which include EntityManagerFactory (for Jpa) and dataSource (for connecting to the database via the JDBC driver) then at the very end it still looks for a factory for the embedded servlet container, raises tomcat,
I see the following in the console
2019-06-21 20:36:08.791 INFO 4640 --- [main] org.hibernate.Version : HHH000412: Hibernate Core {5.3.10.Final}
2019-06-21 20:36:08.797 INFO 4640 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-06-21 20:36:10.838 INFO 4640 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}

further there is all sorts of stuff going on and then I stumble upon
2019-06-21 20:36:21.263 TRACE 4640 --- [ main] ohtype.spi.TypeConfiguration$Scope : Handling #sessionFactoryCreated from for TypeConfiguration
2019-06-21 20: 36:21.267 INFO 4640 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'

i.e. there is no hibernate property, but there is an application property, JPA is also used here, as far as I know this is an abstraction level, but hibernate and spring data already implement it, before hibernate, I somehow tried to make a project on a simple hibernate and there was no spring, but I connected to the memory
<dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.2.18.Final</version>
        </dependency>

and in the resources I wrote hibernate.cfg.xml. Well, this is an example where I understand that I have an action directly with hibernate itself
. As for the datasource bean (which seems to be associated with JDBC), it is still used by my application in the security config (spring security)
, so could you tell me why using spring data i am using hibernate and what is the difference between them and jdbc if it turns out they both use datasource which uses JDBC , Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2019-06-21
@DennisKingsman

JDBC is a database access standard, JPA is a persistence standard, Hibernate is an ORM that implements it, Spring Data is a repository mechanism, and a repository is an abstraction that sits a layer above ORM. That is, Spring Data uses Hibernate and Hibernate uses JDBC.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question