Java Frameworks War: Spring and Hibernate

后端 未结 18 1823
北海茫月
北海茫月 2020-12-23 12:08

My developers are waging a civil war. In one camp, they\'ve embraced Hibernate and Spring. In the other camp, they\'ve denounced frameworks - they\'re considering Hibernate

相关标签:
18条回答
  • 2020-12-23 12:44

    This is one thing (I could remember) that I fell into when I was in my Hibernate days. When you delete (several) child objects from a collection (in a parent entity) and then add new entities to the same collection in one transaction without flushing in the middle, Hibernate will do "insert" before "delete". If the child table has a unique constraint in one of its columns, and you are expecting that you would not violate it since you have already deleted some data before (just like I was), then get ready to be frustrated. Hibernate forum suggests:

    1. It was a DB design flaw, redesign;
    2. flush (or commit if you will) in between the deletes and inserts;

    I couldn't do both, and end up tweaking the Hibernate source and recompiling. It was only 1 line of code. But the effort to find that one line was equal to approximately 27 cups of coffee and 3 sleepless nights.

    This is just one example of problems and quirks you might end up when using Hibernate with no real expert on your team (expert: someone with adequate knowledge about the philosophy and internal working of Hibernate). Your problem, solution, litre of coffee, and sleepless night count may vary. But you get the idea.

    0 讨论(0)
  • 2020-12-23 12:46

    As for Hibernate: a very good tool for application which deals with a rapidly changing database schema, a large amount of tables, do lots of simple CRUD operations. Reports with complex queries involved are rather less well handled. But in these case I prefer mixing in JDBC or native queries. So, for a short answer: I do think time spent learning Hibernate is a good investment (they say it is compliant with EJB3.0 and JPA standards, also, but that didn't come into the equation when I evaluated it for my personal use).

    As for Spring... see The Bile Blog :)

    Remember: frameworks are not silver bullets, but you should not reinvent the wheel either.

    0 讨论(0)
  • 2020-12-23 12:48

    I've used Hibernate a number of times in the past. Each time I've run into edge cases where determining the syntax devolved into a scavenger hunt through the documentation, Google, and old versions. It is a powerful tool but poorly documented (last I looked).

    As for Spring, just about every job I've interviewed for or looked at in the past few years involved Spring, it's really become the de-facto standard for Java/web. Using it will help your developers be more marketable in the future, and it'll help you as you'll have a large pool of people who'll understand your application.

    Writing your own framework is tempting, educational, and fun. Not so great on results.

    0 讨论(0)
  • 2020-12-23 12:48

    The top answer mentions that Hibernate is poorly documented. I agree that the online reference manual could be more complete. However, a book written by Hibernate's authors, 'Java persistence with Hibernate' is a must-read for every Hibernate user and very complete.

    0 讨论(0)
  • 2020-12-23 12:48

    @slim - I am with you again this morning.

    It sounds like a classic case of Not Invented Here Syndrome. If they aren't keen on spring, they should consider other options rather than rolling their own framework (whether they acknowledge doing it or not). Guice comes to mind as an possibility. Also picocontainer. There are others out there, depending on what you need.

    0 讨论(0)
  • 2020-12-23 12:50

    I have to agree with many posts on this one. I've used both, extensively, in a variety of settings. If I could undo a design decision it would be to have used Hibernate. We actually budgeted a release in one of our products to swap Hibernate for iBatis and Spring-JDBC for a best-of-all-worlds approach. I can have a new developer get up to speed using Spring-JDBC, Spring-MVC, Spring-Ioc, and iBatis faster than if I just tasked them with Hibernate.

    Hibernate is just too complicated for this KISS developer. And heaven help you with hibernate if your DBA sees the generated SQL the database sees and sends you back with optimized versions.

    0 讨论(0)
提交回复
热议问题