Spring Data JDBC / Spring Data JPA vs Hibernate

前端 未结 4 524
萌比男神i
萌比男神i 2020-12-02 11:39

What are the typical real life scenarios where one would choose Spring Data JDBC / Spring Data JPA vs Hibernate? I would like to understand the scenarios where either of th

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 12:17

    One problem with your question is you seem to imply that Spring Data JPA is like Hibernate and that's actually not true. Spring Data JPA is merely a spring-centric wrapper that offers springy semantics and features that wrap a JPA provider of which Hibernate is one implementation.

    Ergo, you cannot use Spring Data JPA without including some JPA implementation like Hibernate.

    The base question you're asking then is why use JDBC vs an ORM. In order to understand that you should take time to understand the benefits of an ORM. There are numerous articles on the internet that can give you that.

    But even in an ORM driven application, there will be times where you'll have cases that you need to bypass the ORM framework and use native SQL just like you would in JDBC. Those cases are often rare, but necessary when you want to take advantage of some unsupported database feature or where you want to have ultimate control of manipulating the results, etc.

    The deciding factor on which to use ultimately depends on your application's needs. But just because you elect to use an ORM framework doesn't mutually exclude the ability to execute native queries and SQL statements like you would in JDBC. Those features are still available, you just typically use those in rare cases.

提交回复
热议问题