简体   繁体   English

用数据库开发Java的最佳方法

[英]Best way to develop Java with a DB

I've experience with Toplink to translate objects to database and vica versa. 我有使用Toplink将对象转换为数据库的经验,反之亦然。 But this was all part of a JSP site and now I did some EJB stuff with it to. 但这都是JSP站点的一部分,现在我做了一些EJB的工作。 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? 现在是我的问题:在Java Desktop应用程序中使用诸如Toplink之类的东西好吗?还是使用Java中的本机sql东西更常见?

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. 我正在用Java进行操作,并将数据存储在数据库中。

Thanks 谢谢

ORM is nice if your data model is well structured, not overly complex and, most of all, if you have control over it. 如果您的数据模型结构合理,没有过于复杂,并且最重要的是您可以控制它,那么ORM就是很好的选择。

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. 传统数据库或建模不良的数据库更难用ORM表示,因此不建议这样做,因为您的应用程序将增加模型本身所隐含的复杂性。

If you are comfortable with some ORM tool such as Hibernate and your database is fairly well done, go for it. 如果您对某些ORM工具(例如Hibernate)感到满意,并且数据库做得很好,那就去做吧。 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. 否则,您可能想直接使用JDBC或其他框架来简化JDBC的使用,但仍使用纯SQL。 For such situations I recommend MyBatis . 对于这种情况,我建议使用MyBatis

TopLink (and EclipseLink/JPA) work just as well in a desktop application as in a server side application. TopLink(和EclipseLink / JPA)在桌面应用程序中和在服务器端应用程序中一样好工作。 In fact TopLink has been around since the 90s with client-server Smalltalk apps before the server side was popular. 实际上,TopLink自90年代以来就在客户端服务器Smalltalk应用程序问世之前出现,而服务器端才开始流行。

It's dependent on your use cases 这取决于您的用例

ORM technologies can nicely abstract away database specifics and allow you to concentrate of the domain model. ORM技术可以很好地抽象出数据库的详细信息,并允许您集中精力领域模型。 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). 但是,在某些情况下,不适合使用ORM层(极端大的数据集可能会导致性能问题,例如,很难映射到对象的数据库架构是另一种)。

I would recommend using a JPA compliant technology such as Hibernate. 我建议使用诸如Hibernate之类的JPA兼容技术。 That way you're using the ORM that implements a Java standard and you can more or less swap in and out implementations. 这样,您将使用实现Java标准的ORM,并且可以或多或少地换入和换出实现。

For everything else then JDBC is a flexible friend 对于其他一切,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 可能比写JDBC代码有很大帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM