自动生成数据访问层

发布于 2024-12-27 06:15:11 字数 266 浏览 4 评论 0原文

Hibernate 和 eclipselink 是最流行的 Java DAL 框架。据我了解,它们将程序员创建的对象映射到自动创建的数据库关系和存储过程。

使用此方法与以下方法相比有何优缺点:

  1. 编写您自己的 DAL,假设我的项目是中小型。

  2. 寻找一个框架(如果存在?)以另一种方式 - 从数据库关系和存储过程创建类。

就我个人而言,我觉得推理数据库关系比推理 Java(或任何编程语言)类更舒服。

Hibernate and eclipselink are the most popular DAL frameworks for Java. From what I understand they map object that the programmer created to database relations and stored procedures that are created automatically.

What are the pros and cons of using this method versus:

  1. Writing your own DAL, assuming my project is small-medium sized.

  2. Finding a framework (if exists ?) that will it the other way - create classes from database relations and stored procedures.

Personally, I feel more comfortable with reasoning about database relations rather than Java (or any programming language) classes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瘫痪情歌 2025-01-03 06:15:11

你对JPA的理解是错误的。 JPA(其中 Hibernate 和 EclipseLink 是两个实现)是一个 ORM:对象关系映射器。有些人更喜欢设计 Java 对象并从这些对象推断数据库模式。其他人更喜欢设计数据库模式,并从该模式推导出 Java 对象。

这两种方法都是可能的,并且 JPA 不采用任何一种方法。它指定 Java 对象及其关联如何/必须映射到表。

与编写自己的 DAL 相比,优点是:

  • 您不必这样做,
  • 效率更高,它
  • 是标准的,而且很多开发人员都知道它是如何工作的,
  • 设计得更好,并且错误更少,
  • 您学到的东西可以在许多其他项目中

使用寻找一个从数据库关系创建类的框架:

  • 不适用:JPA就是这样的框架。

Your understanding of JPA is wrong. JPA (of which Hibernate and EclipseLink ar two implementations) is an ORM: Object Relational Mapper. Some prefer designing Java objects and deduce the database schema from these objects. Others prefer designing a database schema, and deduce Java objects from this schema.

Both approaches are possible, and JPA doesn't assume any of those approaches. It specifies how Java objects and their associations can/must be mapped to tables.

Advantages over writing your own DAL:

  • you don't have to,
  • it's much more efficient
  • it's standard, and a whole lot of developers know how it works
  • it's better designed, and has less bugs
  • what you learn will be usable on many other projects

Advantages over finding a framework which creates classes from database relations:

  • Not applicable: JPA is such a framework.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文