Hibernate / Mysql drain for MongoDB or Couch for Java / Spring / Tomcat web application

I have an application that undergoes a massive overhaul, and I studied various options - chug along 'as is', repeat the project in another structure or platform, etc.

When I really think about it, here are 3 main things that I really don't like in java:

  • The server starts / stops when changing controllers or other classes. Dynamic languages ​​are a huge win over Java here.
  • Hibernate, Lazyloading exceptions (especially those that occur during asynchronous service calls or during Jackson JSON sorting) and bloating ORM in general. Hibernate, by itself, is responsible for the slow integration startup time and the insanely slow application launch time.
  • Obvious stupidity - inconsistent problems with loading classes when starting the application inside your IDE compared to Tomcat. Provided after you fix these issues, you will most likely not see them again. However, most of them are actually caused by Hibernate, as it insists on a specific version of Antlr, etc.

Thinking about the problem ... I could solve or at least improve the situation in all three of these areas if I just got rid of Hibernate.

Have any of you recycle a Java + 50+ application to use mongo or couch or a similar database? What was the experience like? Did you recommend it? How long do you think you have pretty good unit / integration tests? Does the idea sound better than it really is?

My application will really benefit in many areas if I can store documents. It really will open up some interesting and interesting features for this application. However, I like to create dynamic queries for complex searches ... and I am told that Couch cannot do this.

I'm really green when it comes to NoSQL databases, so any advice on migrating (or not migrating) a large java / spring project would be really helpful. Also, if it is a good idea, which books would you recommend, I am taking away to speed up and really use them for this application in the best way?

thanks

+4
source share
3 answers

In any case, your disclosure not only affects the problems with the previously adopted (hereditary) solution for Hibernate, but also with your development as a programmer as a whole.

This is how I will do it if such a project is dropped on my lap and is in urgent need of refactoring or improvement.

It depends on the stage of the life cycle of your software and the time when you have to make big changes or stick to smaller ones. However, migrating in steps will be the best option in the long run.

Keeping the application written in Java in the short term seems reasonable, serious processing in another language will certainly violate acceptance and integration tests.

As Joseph suggested, take a step from Hibernate to JPA. It should not cost too much time. And from there you can switch the back-end to another storage method. Work to share problems. Choose any concept that works best, some prefer MVC, others can choose CQRS, and others love a different segmentation / separation style.

Since the JVM supports many languages, you can always switch to any of them or at least partially implement the functionality in more dynamic languages. This will solve part of the problem when you continue to encounter the "stupidity" of Java, while maintaining excellent optimization of the current JVMs at runtime.

In addition, you can configure automatic integration tests ... since the application, I hope, will never be launched from your IDE, these tests will give you honest results.

Note: I never trust my IDE to get dependencies correctly if the IDE has the ability to inject its own libraries into my build or run path.

So, briefly outline: small steps; lose Hibernate and move more abstractly to JPA; if Java becomes stupid, then gradually switch to a smart language. Your main task should be to rebuild the code base without losing functionality, bearing in mind an open design that will make it easier to add interesting and interesting functions later.

+1
source

Well, a lot depends on things like "what kind of pain points with Hibernate?" (I know you gave three examples ...)

But these are not major problems in the long run. What you come across is the nature of the compiled language and the dynamic; while working, it works better for you (since Java is faster and more scalable than dynamic languages ​​based on my not-so-comprehensive tests), but during development, it is less amenable to just hacking shit together and hoping it works.

NoSQL is not going to correct the situation, although document stores can, but there is a transition step that you have to go through.

Important: I work for a supplier in this space, which explains my experience in this area, as well as the bias in the following paragraph:

You focus on open source projects, I suppose, although I would suggest using a commercial product: GigaSpaces (http://gigaspaces.com). There is a community version that will allow you to transfer JPA java objects to the document model (via the SpaceDynamicProperties annotation); you can use JPA for the code you wrote, and slowly transfer it to a fully document-oriented model at a time convenient for you, and complex queries are not a problem.

0
source

All of these points usually cause problems due to incompetence, rather than hibernation or java being problematic:

  • in addition to structural changes (adding fields or methods), all changes in java code are hot-swappable in debug mode, so you can save and test (without any redeployment).

  • LazyInitializationException is a problem only for hibernation beginners. There are many clear solutions, and you will find them with a simple google or SO search. And you can always set your collections to fetch=FetchType.EAGER . Or you can use Hibernate.initialize(..) to initialize lazy collections.

  • It is only natural that a specific version of another library is required for the library (the opposite would be suspicious and incorrect). If you save your path clean class (for example, using maven or ivy), you will not have problems with loading. I've never been.

Now I will provide an alternative. spring-data is a new springsource portfolio project that allows you to use your entities for a bunch of NoSQL repositories.

0
source

All Articles