开发者

How to simplify Spring/Hibernate combo without going to Roo

In the last year, has there been any new developments in simplifying this combo, or is it basically the same as it always was?

I don't really like a lot of the new RAD frameworks/platforms (Rails, etc.). I think they are great for small apps, or proof of concepts... but I usually get so annoyed with their shortcomings pretty quickly when I move on to complex requirements. Rails in particular has many issues - surprisingly far too many that actually slowed me down compared to how long it would have taken me in Java... things that I think most people would never run into ever... or perhaps never run into until their honeymoon period was over with.

I would simply rather have the power and reliability of Spring/Java in many cases, even it means it will take me longer to develop the application. I feel comfortable with that. I trust it. I know how to deploy it. It works, and it works well for large applications.

I'd really like to improve my development experience as much as possible. I'm looking for what people usually like using for large-scale, web 2.0 (ria) type of projects these days in their Spring/Hibernate projects (or Spring/Whatever works too I guess...).

  1. I'm pretty convinced that dbunit is outdated, and is a large source of my testing performance problems. Is there anything similar to a factory girl, but for java?

  2. Is there any way to make links more "application-like", rather than just loose-strings? I tend to refactor urls a lot, and manually testing the application to ensure nothing breaks is kind of a big pain. I'd appreciate any solutions to this. I use Freemarker/Spring MVC currently.

  3. I am finding that I need to use more and more AJAX in my applications. Simple ajax is fine, but currently I have to use Jackson to parse incoming request JSON before it goes to a Spring MVC controller. A lot of this parsing/mapping is very time-consuming. There has to be a better way. Is there? I don't want to program parsers/object mappers for incoming JSON requests to my controller tier anymore.

  4. One of the things I really liked in Rails was the ability to piece queries together and have reusable query pieces. I forget what they called them. Is there a way to do this using Hibernate/Spring? I have a lot of queries that use massive HQL strings, and a lot of the time, segments of these queries are just repeated over and over again throughout the application. I'd like to reuse what I can here. Can it be done?

  5. I typically run into far too many small problems when I deploy that would never be caught when testing. Hibernate proxy bugs and weird lazy-loading issues are on the top of this list, but even annotation problems with Spring MVC controllers and a variety of other issues can crop up that are hard to test (or maybe impossible to test?). What are some solutions to these kinds of problems? Not use Hibernate? Do some other kind of testing? What works? I don't mind doing testing, but I want it to be fast, o开发者_Python百科therwise I will probably get aggravated and will refuse to do it.

  6. Generally anything else you think would help productivity that I may not have heard about. Unfortunately, I haven't been too active at all in the Java space for awhile, so I am behind. I need a little bit of "Here is what is available now" type of advice.

Thanks!


I'll only answer the ones I know about...

2. We have done something like this in our application with a custom tag library, but that's obviously only useful if you're using JSTL. Have you considered creating a class which contains all the URLs as static final Strings, then adding that class to Freemarker as a shared variable? Your @RequestMapping annotations in Spring MVC should then be able to refer to those same static final Strings.

3. I recommend Direct Web Remoting — it handles AJAX calls automatically for you, both on the server and client site. Once set up it's just a matter of annotating the Java methods that you want to call from Javascript code, and then DWR generates Javascript code that makes those calls for you and translates the return values into Javascript objects. DWR hasn't had active development for a while, but I've found it very stable and reliable.

5. With regard to Hibernate lazy loading in particular, we just enable Spring's org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor which keeps a single session open for the entire web request. It eliminates lazy loading errors, and makes the behaviour of Hibernate easier to understand (ie because you're always in a session, all updates are committed to the database). If you're going to do this, do it at the start of development... otherwise existing code could be broken because if it assumes a session is closed.

6. If your site is more web application than web site, consider building it with Vaadin. It's an open-source RIA framework build on GWT, and we use it quite successfully with Spring and Hibernate. We use Vaadin for the 'application-like' parts such as administration tools, and Spring MVC / JSTL for the 'web-like' parts such as public-facing pages; both are built into the same WAR with the same Spring / Hibernate business layer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜