简体   繁体   English

为Java / Spring / Tomcat Web应用程序淘汰MongoDB或Couch的Hibernate / Mysql

[英]Ripping out Hibernate/Mysql for MongoDB or Couch for a Java/Spring/Tomcat web application

I have an application that is undergoing massive rework, and I've been exploring different options - chug along 'as is', redo the project in a different framework or platform, etc. 我有一个正在进行大规模返工的应用程序,我一直在探索不同的选项 - “按原样”进行调整,在不同的框架或平台中重做项目等。

When I really think about it, here are 3 major things I really dislike about java: 当我真的想到它时,这里有三个我不喜欢java的主要内容:

  1. Server start/stops when modifying controllers or other classes. 修改控制器或其他类时服务器启动/停止。 Dynamic languages are a huge win over Java here. 动态语言在这里是对Java的巨大胜利。
  2. Hibernate, Lazyloading exceptions (especially those that occur in asynchronous service calls or during Jackson JSON marshalling) and ORM bloat in general. Hibernate,Lazyloading异常(特别是在异步服务调用或Jackson JSON编组期间发生的异常)和ORM膨胀。 Hibernate, all by itself, is responsible for slow integration start up times and insanely slow application start up times. Hibernate本身就是缓慢的集成启动时间和极其缓慢的应用程序启动时间的原因。
  3. Java stupidity - inconsistent class-loading problems when running your app inside of your IDE compared to Tomcat. Java愚蠢 - 与Tomcat相比,在IDE中运行应用程序时出现的类加载问题不一致。 Granted once you iron out these issues, you most likely won't see them again. 一旦你解决了这些问题,你很可能再也看不到它们了。 Even still, most of these are actually caused by Hibernate since it insists on a specific Antlr version and so on. 即便如此,其中大部分都是由Hibernate引起的,因为它坚持使用特定的Antlr版本等等。

After thinking about the problem... I could solve or at least improve the situation in all 3 of these areas if I just got rid of Hibernate. 在思考问题之后......如果我摆脱Hibernate,我可以解决或至少改善所有这三个方面的情况。

Have any of you reworked a 50+ entity java application to use mongo or couch or similar database? 你有没有重新设计50多个实体java应用程序来使用mongo或沙发或类似的数据库? What was the experience like? 经历是什么样的? Do you recommend it? 你推荐它吗? How long did it take you assuming you have some pretty great unit/integration tests? 假设你有一些非常棒的单元/集成测试需要多长时间? Does the idea sound better than it really is? 这个想法听起来比实际更好吗?

My application would actually benefit in many areas if I could store documents. 如果我可以存储文档,我的应用程序实际上会在许多方面受益。 It would actually open up some very cool and interesting features for this application. 它实际上会为这个应用程序打开一些非常酷和有趣的功能。 However, I do like being able to create dynamic queries for complex searches... and I'm told that Couch can't do those. 但是,我确实希望能够为复杂的搜索创建动态查询......而且我被告知Couch不能这样做。

I'm really green when it comes to NoSQL databases, so any advice on migrating (or not migrating) a big java/spring project would be really helpful. 对于NoSQL数据库,我真的很环保,所以任何有关迁移(或不迁移)大型java / spring项目的建议都会非常有用。 Also, if this is a good idea, what books would you recommend I pick up to get me up to speed and really make use of them for this application in the best way possible? 另外,如果这是一个好主意,你会推荐哪些书籍让我加快速度,并以最好的方式真正利用它们来应用这个应用程序?

Thanks 谢谢

In any way, your rant doesn't just cover problems with the previously made (legacy) decision for Hibernate but also with your development as a programmer in general. 无论如何,你的咆哮不仅仅包括先前为Hibernate做出的(传统)决定的问题,还包括你作为程序员的开发。

This is how I would do it, should a similar project be dropped in my lap and in dire need of refactoring or improvement. 如果类似的项目放在我的膝盖上并且急需重构或改进,我就会这样做。

It depends on the stage in your software's lifetime and the time pressure involved if you should make big changes or stick with smaller ones. 这取决于软件生命周期的阶段以及如果您要进行重大更改或坚持使用较小的更改所涉及的时间压力。 Nevertheless, migrating in increments seems to be your best option in the long term. 然而,从长远来看,以增量进行迁移似乎是您的最佳选择。

Keeping the application written in Java for the short term seems wise, a major rewrite in another language will definitely break acceptance and integration tests. 保持短期内用Java编写的应用程序似乎是明智之举,另一种语言的重大改写肯定会破坏接受和集成测试。

Like suggested by Joseph, make the step from Hibernate to JPA. 像约瑟夫建议的那样,从Hibernate迈向JPA。 It shouldn't cost too much time. 它不应该花费太多时间。 And from there you can switch the back-end to some other way of storage. 从那里你可以将后端切换到其他一些存储方式。 Work towards a way of seperating concerns. 努力解决问题。 Pick whatever concept seems best, some prefer MVC while others might opt for CQRS and still others adore another style of segmentation/seperation. 选择看起来最好的概念,有些人更喜欢MVC而其他人可能会选择CQRS,还有一些人喜欢另一种分割/分离方式。

Since the JVM supports many languages, you can always switch to any of those or at least partially implement functionality in more dynamic languages. 由于JVM支持多种语言,因此您始终可以切换到其中任何一种语言,或者至少部分地以更动态的语言实现功能。 This will solve part of the problem where you keep bumping into the "stupidity" of Java, while still retaining the excellent optimizations of current JVMs at runtime. 这将解决部分问题,即您不断碰到Java的“愚蠢”,同时仍然保留当前JVM在运行时的出色优化。

In addition, you might want to set up automatic integration tests... since the application will hopefully never be run from your IDE, these tests will give you honest results. 此外,您可能希望设置自动集成测试...因为希望永远不会从IDE运行应用程序,所以这些测试将为您提供真实的结果。

Side note: I never trust my IDE to get dependencies right if the IDE has capabilities to inject its own libraries into my build or runtime path. 旁注:如果IDE具有将自己的库注入构建或运行时路径的功能,我从不相信我的IDE能够正确获取依赖关系。

So to recap in short: small steps; 简而言之:小步骤; lose Hibernate and go more abstract to JPA; 失去Hibernate并对JPA更加抽象; if Java becomes stupid, then gradually switch to a clever language. 如果Java变得愚蠢,那么逐渐转向一种聪明的语言。 Your primary concern should be to restructure the code base without losing functionality, keeping in mind to have an open design which will make adding interesting and cool features easier later on. 您主要关注的是重构代码库而不会丢失功能,请记住,开放式设计将使以后更容易添加有趣和酷炫的功能。

Well, much depends on things like "what exactly are the pain points with Hibernate?" 嗯,很大程度上取决于“Hibernate的痛点究竟是什么?” (I know, you gave three examples...) (我知道,你举了三个例子......)

But those aren't core issues over the long haul. 但从长远来看,这些不是核心问题。 What you're running into is the nature of a compiled language vs. a dynamic one; 你遇到的是编译语言与动态语言的本质; at runtime, it works out better for you (as Java is faster and more scalable than the dynamic languages, based on my not-quite-exhaustive tests), but at development time, it's less amenable to just hacking crap together and hoping it works. 在运行时,它对您来说效果更好(因为Java比动态语言更快,更具可扩展性,基于我不太详尽的测试),但在开发时,它不太可能只是破解垃圾并希望它的工作原理。

NoSQL isn't going to fix things, although document stores could, but there's a migration step you're going to have to go through. 虽然文档存储可以,NoSQL不会解决问题,但是你需要经历一个迁移步骤。

Important: I work for a vendor in this space, which explains my experience in the area, as well as the bias in the next paragraph: 重要提示:我为这个领域的供应商工作,这解释了我在该领域的经验,以及下一段中的偏见​​:

You're focusing on open source projects, I suppose, although what I would suggest is using a commercial product: GigaSpaces (http://gigaspaces.com). 我想,你专注于开源项目,虽然我建议使用商业产品:GigaSpaces(http://gigaspaces.com)。 There's a community edition, that would allow you to migrate JPA-based java objects to a document model (via the SpaceDynamicProperties annotation); 有一个社区版本,允许您将基于JPA的java对象迁移到文档模型(通过SpaceDynamicProperties批注); you could use JPA for the code you've written and slowly migrate to a fully document-oriented model at your convenience, plus complex queries aren't an issue. 您可以将JPA用于您编写的代码,并在您方便时慢慢迁移到完全面向文档的模型,此外复杂的查询也不是问题。

All of those points are usually causing problems due to incompetence, rather than hibernate or java being problematic: 所有这些点通常都会因为无能而导致问题,而不是休眠或java存在问题:

  • apart from structural modifications (adding fields or methods), all changes in the java code are hot-swapped in debug mode, so that you can save & test (without any redeploy). 除了结构修改(添加字段或方法)之外,java代码中的所有更改都在调试模式下进行热交换,因此您可以保存和测试(无需任何重新部署)。

  • the LazyInitializationException is a problem for hibernate-beginners only. LazyInitializationException仅适用于hibernate-beginners。 There are many and clear solutions to it, and you'll find them with a simple google or SO search. 有很多明确的解决方案,您可以通过简单的谷歌搜索或搜索结果搜索找到它们。 And you can always set your collections to fetch=FetchType.EAGER . 您始终可以将集合设置为fetch=FetchType.EAGER Or you can use Hibernate.initialize(..) to initialize lazy collections. 或者您可以使用Hibernate.initialize(..)来初始化延迟集合。

  • It is entirely normal for a library to require a specific version of another library (the opposite would be suspicious and wrong). 库需要另一个库的特定版本是完全正常的(相反的是可疑和错误的)。 If you keep your classpath clean (for example by using maven or ivy), you won't have any classloading issues. 如果你保持你的类路径干净(例如通过使用maven或常春藤),你将不会有任何类加载问题。 I have never had. 我从来没有过。

Now, I will provide an alternative. 现在,我将提供一个替代方案。 spring-data is a new portfolio project by springsource, that allows you to use your entities for a bunch of NoSQL stores. spring-data是一个由springsource组成的新项目组合项目,它允许您将实体用于一堆NoSQL存储。

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

相关问题 在 jetty 和 tomcat 上运行 spring hibernate web 应用程序 - running a spring hibernate web application on jetty and tomcat Tomcat-Spring-Hibernate Web应用程序中的“PermGen out of space”异常可以做些什么? - What can be done with 'PermGen out of space' exception in Tomcat-Spring-Hibernate web application? 在Tomcat Web应用程序中使用Java和MySQL进行连接池 - Connection pooling with Java and MySQL in Tomcat web application 使用Spring,Hibernate,Tomcat和MySQL Community Server运行我的应用程序 - Running my application with Spring, Hibernate, Tomcat, and MySQL Community Server Java spring / spring boot Application: Web logic to Tomcat conversion - Java spring / spring boot Application : Web logic to Tomcat conversion 在基于Spring-Hibernate的Web应用程序中创建JAR - Create JAR out of a Spring-Hibernate based Web Application Java Web应用程序,tomcat 6 - Java Web application ,tomcat 6 在Spring-Hibernate Web应用程序中编写Java应用程序 - Writing a java application within a Spring-Hibernate web application 在Tomcat7下的Java Web应用程序项目中将Akka与Spring集成 - Integrate Akka with Spring in Java web application project under Tomcat7 将Java应用程序(使用Spring的Web和桌面应用程序)与mongodb连接 - Connecting Java Application (Web and Desktop application using spring) with mongodb
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM