使用 DB 开发 Java 的最佳方式
我有使用 Toplink 将对象转换为数据库的经验,反之亦然。但这都是 JSP 站点的一部分,现在我用它做了一些 EJB 的东西。现在我的问题是:在 Java 桌面应用程序中使用像 Toplink 这样的东西好还是使用 Java 中的本机 sql 东西更常见?
也许教授的一些经验。开发商可能不错。我需要为客户开发一个认真的应用程序。我用 Java 来做这件事,并将数据存储在数据库中。
谢谢
I've experience with Toplink to translate objects to database and vica versa. But this was all part of a JSP site and now I did some EJB stuff with it to. Now is my question: is it good to work with stuff like Toplink in a Java Desktop application or is it more common to use native sql stuff from Java?
Maybe some experience of prof. developpers might be good. I need to develop a seriously application for a client. I'm doing it in Java and I'm gonna store the data in a database.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您的数据模型结构良好、不过于复杂,而且最重要的是您可以控制它,那么 ORM 就很好。
遗留数据库或建模不佳的数据库很难用 ORM 表示,并且强烈建议不要这样做,因为您的应用程序会比模型本身隐含的复杂性增加更多的复杂性。
如果您对某些 ORM 工具(例如 Hibernate)感到满意,并且您的数据库做得相当好,那就去吧。它们确实为您节省了大量的样板代码,并且在幕后有一些很好的查询优化代码。否则,您可能希望直接使用 JDBC 或其他框架来简化 JDBC 使用,但仍使用纯 SQL。对于这种情况,我推荐 MyBatis。
ORM is nice if your data model is well structured, not overly complex and, most of all, if you have control over it.
Legacy databases or poorly modelled ones are harder to be represented with ORM, and doing so would be strongly discouraged, as your application would add further complexities over those implied by the model itself.
If you are comfortable with some ORM tool such as Hibernate and your database is fairly well done, go for it. They sure save you a lot of boilerplate code and have some nice query optimization code under the hood. Otherwise, you may want to use JDBC directly or some other framework to simplify JDBC use but still using plain SQL. For such situations I recommend MyBatis.
TopLink(和 EclipseLink/JPA)在桌面应用程序中与在服务器端应用程序中一样工作。事实上,在服务器端流行之前,TopLink 自 20 世纪 90 年代以来就已经出现了客户端-服务器 Smalltalk 应用程序。
TopLink (and EclipseLink/JPA) work just as well in a desktop application as in a server side application. In fact TopLink has been around since the 90s with client-server Smalltalk apps before the server side was popular.
这取决于您的用例,
ORM 技术可以很好地抽象出数据库细节,并允许您专注于领域模型。然而,在某些情况下,使用 ORM 层是不合适的(极大的数据集可能会导致性能问题,例如,难以映射到对象的数据库模式是另一个问题)。
我建议使用符合 JPA 的技术,例如 Hibernate。这样,您就可以使用实现 Java 标准的 ORM,并且可以或多或少地换入和换出实现。
对于其他一切,JDBC 都是一个灵活的朋友
It's dependent on your use cases
ORM technologies can nicely abstract away database specifics and allow you to concentrate of the domain model. However, there are circumstances where using an ORM layer is not appropriate (extremely large data sets can cause performance issues for example, database schemas that are difficult to map to objects is another).
I would recommend using a JPA compliant technology such as Hibernate. That way you're using the ORM that implements a Java standard and you can more or less swap in and out implementations.
For everything else then JDBC is a flexible friend
也取决于数据库容量。对于拥有大量数据的数据库,请尝试使用 hibernate。它可能比编写 JDBC 代码有很大帮助
depends on database volume too. For databases with huge data try using hibernate. It might be of great help rather than writing JDBC code