JPA vs Spring JdbcTemplate [英] JPA vs Spring JdbcTemplate

查看:576
本文介绍了JPA vs Spring JdbcTemplate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一个新项目,JPA始终是处理关系数据的推荐工具,还是有些情况下Spring JdbcTemplate是更好的选择?您的回复中需要考虑的一些因素:

For a new project is JPA always the recommended tool for handling relational data or are there scenarios where Spring JdbcTemplate is a better choice? Some factors to consider in your response:


  • 新数据库架构与预先存在的架构和表格

  • 开发人员专业水平

  • 与数据缓存层集成的简便性

  • 性能

  • 任何其他相关因素需要考虑?

  • new database schema vs pre-existing schema and tables
  • level of developer expertise
  • ease with which can integrate with a data caching layer
  • performance
  • any other relevant factors to consider?

推荐答案

如果您不想访问,请使用Spring JdbcTemplate您的数据库架构通过域模型。使用JdbcTemplate,您使用较低级别的访问,具有更大的灵活性,但可能还有更多的样板。

Use Spring JdbcTemplate if you don't want to access your database schema via a domain model. Using JdbcTemplate you are using a lower level access, with more flexibility, but probably also more boilerplate.

Spring JdbcTemplate可以更容易地与异国情调的数据库模式和存储过程一起使用焦点。使用JPA,您需要确保数据库模式正确映射到域模型。

Spring JdbcTemplate can be more easily used with exotic database schemas and a stored procedure focus. Using JPA you need to make sure that database schema maps correctly to the domain model.

这两种技术都需要开发人员了解关系数据库,SQL和事务。使用JPA,你可以获得更多隐藏的复杂性。

Both technologies need developers knowing relational databases, SQL and transactions. With JPA you get more hidden complexity though.

据我所知,JPA更容易插入数据缓存层,因为面向对象的焦点使得缓存条目识别,更新和失效更容易。

JPA is to my knowledge more easily pluggable to data caching layers, since the object oriented focus makes cache entry identification, update and invalidation easier.

您可以更好地调整基于JdbcTemplate的后端,但在大多数情况下会涉及更多代码。

You can fine tune JdbcTemplate based backends better, but there is for most cases more code involved.

需要考虑的另一个方面是,尽管使用JPA,您获得了数据库模式的域模型,但您通常需要使用其他DTO类。使用JdbcTemplate,您可以直接使用DTO类。

Some other aspect to consider is that although with JPA you get a domain model for your database schema you will often need to use additional DTO classes. Using JdbcTemplate you can directly operate with DTO classes.

这篇关于JPA vs Spring JdbcTemplate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆