Java - JDBC替代品 [英] Java - JDBC alternatives

查看:230
本文介绍了Java - JDBC替代品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这只是理论上的问题。

我在我的Java应用程序中使用JDBC来使用数据库(选择,插入,更新,删除或其他)。
我制作手动Java类,它将包含来自DB表的数据(attribute = db列)。然后我进行查询(ResultSet)并用数据填充这些类。我不确定,如果这是正确的方法。

I use JDBC with my Java applications for using database (select, insert, update, delete or whatever). I make "manually" Java classes which will contain data from DB tables (attribute = db column). Then I make queries (ResultSet) and fill those classes with data. I am not sure, if this is the right way.

但我已经阅读了很多关于JDO和其他持久性解决方案的内容。

But I've read lot of about JDO and another persistence solutions.

有人可以根据他们的经验推荐最佳使用的JDBC替代品吗?

Can someone please recommend the best used JDBC alternatives, based on their experience?

我还想知道JDO优于JDBC的优势(在简单的话)。

I would also like to know the advantages of JDO over JDBC (in simple words).

我已经能够对这些东西进行谷歌搜索,但是第一手的意见总是最好的。

I've been able to google lot of this stuff, but opinions from the "first hand" are always best.

谢谢

推荐答案

Java中数据库持久性的故事已经漫长而充满曲折:

The story of database persistence in Java is already long and full of twists and turns:


  • JDBC 每个人都使用的低级API最后与数据库交谈。但是,如果不使用更高级别的API,则必须自己完成所有繁琐的工作(编写SQL查询,将结果映射到对象等)。

  • JDBC is the low level API that everybody uses at the end to talk to a database. But without using a higher level API, you have to do all the grunt work yourself (writing SQL queries, mapping results to objects, etc).

EJB 1.0 CMP Entity Beans 是更高级别API的第一次尝试,并且已被大型Java EE提供程序(BEA,IBM)成功采用,但未被用户成功采用。实体Bean太复杂,开销太大(理解,性能不佳)。 失败!

EJB 1.0 CMP Entity Beans was a first try for a higher level API and has been successfully adopted by the big Java EE providers (BEA, IBM) but not by users. Entity Beans were too complex and had too much overhead (understand, poor performance). FAIL!

EJB 2.0 CMP 尝试通过介绍减少Entity Beans的一些复杂性本地接口,但大多数复杂性仍然存在。 EJB 2.0也缺乏可移植性(因为对象关系映射不是规范的一部分,因此部署描述符是专有的)。 失败!

EJB 2.0 CMP tried to reduce some of the complexity of Entity Beans with the introduction of local interfaces, but the majority of the complexity remained. EJB 2.0 also lacked portability (because the object-relational mapping were not part of the spec and the deployment descriptor were thus proprietary). FAIL!

然后来了 JDO 数据存储区不可知标准用于对象持久性(可以与RDBMS,OODBMS,XML,Excel,LDAP一起使用)。但是,虽然有几个开源实现,虽然JDO已被小型独立供应商采用(大多数OODBMS供应商希望JDO用户稍后会从他们的RDBMS数据存储切换到OODBMS - 但这显然从未发生过),但它未能成为由大型Java EE玩家和用户采用(因为编织在开发时很痛苦并且吓到了一些客户,一个奇怪的查询API,实际上太抽象)。因此,虽然标准本身并没有死,但我认为它是失败的。 失败!

Then came JDO which is a datastore agnostic standard for object persistence (can be used with RDBMS, OODBMS, XML, Excel, LDAP). But, while there are several open-source implementations and while JDO has been adopted by small independent vendors (mostly OODBMS vendors hoping that JDO users would later switch from their RDBMS datastore to an OODBMS - but this obviously never happened), it failed at being adopted by big Java EE players and users (because of weaving which was a pain at development time and scaring some customers, of a weird query API, of being actually too abstract). So, while the standard itself is not dead, I consider it as a failure. FAIL!

事实上,尽管存在两个标准,如 Toplink 等专有API,老用户或 Hibernate 已被用户优先于EJB CMP和JDO用于对象关系数据库持久性(标准之间的竞争,JDO的定位不明确,CMP的早期失败和糟糕的营销都有责任的一部分)在这个我相信)和Hibernate实际上成为这个领域的事实上的标准(它是一个伟大的开源框架)。 成功!

And indeed, despite the existence of two standards, proprietary APIs like Toplink, an old player, or Hibernate have been preferred by users over EJB CMP and JDO for object to relational database persistence (competition between standards, unclear positioning of JDO, earlier failure of CMP and bad marketing have a part of responsibility in this I believe) and Hibernate actually became the de facto standard in this field (it's a great open source framework). SUCCESS!

然后Sun意识到他们必须简化事情(更普遍的是整个Java EE),他们用Java做到了EE 5,带有 JPA ,Java Persistence API,它是EJB 3.0的一部分,是对象到关系数据库持久性的新标准。 JPA统一了EJB 2 CMP,JDO,Hibernate和TopLink API /产品,似乎在EJB CMP和JDO失败的地方取得了成功(易于使用和采用)。 成功!

Then Sun realized they had to simplify things (and more generally the whole Java EE) and they did it in Java EE 5 with JPA, the Java Persistence API, which is part of EJB 3.0 and is the new standard for object to relational database persistence. JPA unifies EJB 2 CMP, JDO, Hibernate, and TopLink APIs / products and seems to succeed where EJB CMP and JDO failed (ease of use and adoption). SUCCESS!

总结一下,Java的数据库持久性标准 JPA 并且应优先于其他专有API(使用Hibernate的JPA实现很好,但使用JPA API),除非ORM不是您需要的。它提供了比JDBC更高级别的API,旨在为您节省大量的手工工作(这是简化的,但这就是想法)。

To summarize, Java's standard for database persistence is JPA and should be preferred over others proprietary APIs (using Hibernate's implementation of JPA is fine but use JPA API) unless an ORM is not what you need. It provides a higher level API than JDBC and is meant to save you a lot of manual work (this is simplified but that's the idea).

这篇关于Java - JDBC替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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