The No.1 i-Technology Magazine in the World !
   
 

      ES no BS
This is a personal blog of Yakov Fain       My son's animations and music         No BS IT podcast      Америчка




Archives

««Aug 2010»»
SMTWTFS
1234567
891011121314
15161718192021
22232425262728
293031

RSS Feed








Subscribe to these blogs

This Java architecture is a tough sell

posted Friday, 27 March 2009

Three years ago I've suggested a light architecture for Web/J2EE applications that was based on a Servlet container with transaction processing, Message Oriented Middleware, and a DBMS: http://java.sys-con.com/node/204697 . This  piece was a part of an old and  semi-serious Gas Station series published at Java Developer's Journal.

Even though during the last three years I was predominantly involved with the client side part, I've been watching closely what's happening in the Java EE domain.

Today, I was discussing an architecture of a new Flex/Java application with a colleague, and we came up with even lighter architecture: Flex-AMF protocol-JavaServlet+Transaction support library-DBMS with potential introduction of asynchronous messaging, if need be. I want to stress - only if there will be a need to scale, adding it on the protocol level so the application developers won't even notice it. We've learned how to seriously scale well designed Jetty's servlet container empowered by Adobe's BlazeDS ( it's a pity that Jetty-based early draftsof JSR 315 has been buried, which deserves a separate article).

No EJB or Spring container, no Hibernate either - just tried and true SQL/JDBC. 

After the conversation was over, I've had this deja vu feeling and recalled that old article. On one hand, I still believe that this is the right way to architect Web applications, but  on the other hand I know that it'll be a tough sell -  selling an architecture at a gas station is not the same as selling to Wall Street IT architects. This application will be developed for large corporate clients, which implies that I'll need to present and defend this architecture in front of the architecture groups of these corporations. 

EJB are out of style these days. In the Java world, the buzzwords of the first decade of this Century are Spring and Hibernate. If the PowerPoint won't include such boxes on the architectural diagram, most likely the enterprise architects won't approve it. Now I need to decide if I want to be 100% honest and jeopardize more efficient design, or be street smart, add these two boxes to the slide show, and when the project will be approved, quietly or with a fist fight remove them one by one.

I need to be very careful.
I need to think hard.
I need to consult with sales people.
I need to be smart.
I need to be politically correct.
Repeat.

tags:    

links: digg this    del.icio.us    technorati    




1. Ben left...
Saturday, 28 March 2009 11:29 am

i have given up on EJB long ago. Its simply too complicated and unproductive. Looks good on paper but... I guess Spring and Hibernate are the new kids on the block. My perception is that Spring and Hibernate too is getting a little too complicated. It's Law of Add-Ons and Complexities "If a simple architecture works; invariably it will attract attentions and someone will come along and put more add-ons and complexities over time and will be its demise..."


2. Valery left...
Thursday, 2 April 2009 8:31 am

Ben, Neither Spring nor Hibernate are new kids. Both are very mature products. I can agree with you that both looks complex from first sight, but this is a false impression, at least for Hibernate: 1. You may use it even now (3.x) as good old Hibernate 2.0 with no annotations or any other new stuff. 2. You may use it with Hibernate annotations 3. You may use it with standard JPA annotations (and optionally mix Hibernate annotations when functionality is not covered by JPA) 4. You may use it with EntityManager and your code will be JPA compliant (i.e. no references to Hibernate at all). Note that (3) does not mandate (4) 5. You may add full-text search a top of any option 6. Etc...

So it's absolutely up to you how much Hibernate to use. You may add plain SQL if this is ultimately necessary. You may use DTO along with Entities (this is frequently practical for reporting-like functionality), or with no Entities at all (extreme case, but still possible).

Talking about Spring, for me it is not geeky enough... )))) Seriously, I find a way it's configured too complex. My own preference is Google Guice + Hibernate + Warp Persist. This combo works amazing in our current project: -- it's simple (just read Google Guice and Warp Persist docs -- the documentation is small, but, man -- it's complete!) -- majority of code (business objects, data access layer) is declarative, so it's easier to develop, easier to understand and maintain -- there is only one type of sources, and this is Java sources, so no need for sluggish Eclipse/IntelliJ IDEA plugins to support Spring XML, any descent Java IDE may do refactorings quickly and reliably.

Yakov, do you have any own negative experience with Hibernate? Or you always abandon it as a choice preliminary?


3. Yakov Fain left...
Thursday, 2 April 2009 7:24 pm

Valery,

You start your comment with a premise that people have to use one of these technologies, and then suggest that it's "up to you how much of Hibernate to use". Why wouldn't you spend some time explaining WHY use any of these technologies at all? Do you see anything wrong with a simple architecture that I've suggested?


4. Valery left...
Friday, 3 April 2009 7:32 am

Yakov, ok.

Here is 3 major reasons why I'd recommend Hibernate/JPA over plain JDBC for development.

1. You need SQL-to-Object mapping anyway, at least to pass object graph back and force between J2EE server/servlet container and Flex client. You can't pass java.sql.ResultSet over the wire (sure, you can pass XML form of javax.sql.RowSet, but I'm still to see who uses this approach). If you need ORM anyway, then why not use existing mature and proven ORM tool? Ain't rolling your own mapping layer is more time consuming and error-prone?

2. Maintaining/refactoring Hibernate application is simpler than plain JDBC. Majority of data access code (everything besides HQL queries typically) is generated automatically. Less manually written code -- less code to maintain. In case of changes to requirements you may easily and reliably extend/refactor Java object model, instead of fixing numerous hand-written INSERT/UPDATE/DELET SQL statements. And requirements changes happen very frequently during development, typically in form of "clarifications" that seriously affects object model design. Consequences of "agile specification development", you know...

3. Unfortunately, "SQL smarties" is the most rare human resource in application development. So, in case a development team is lucky enough to have at least one on board, then a good tool like Hibernate let him/them maximize productivity. They can do more advanced tasks in shorter term (like designing efficient model and writing efficient queries) while they are free from mundane/dumb work (like writing insert/update/delete for every entity, correctly closing result sets and statements, mapping cryptic SQL exceptions to more usable ones).

Btw, if no one from the team has good SQL knowledge, then nothing will help the project. Neither Hibernate, nor JDBC -- ones who don't know SQL hardly can do any good JPA model or write efficient HQL.

Probably, you assume using Farata's Clear Data Builder in the project, though this is not explicitly mentioned in the post. Then it's the same case as with Hibernate -- you don't suggest using JDBC/SQL directly, you are suggesting instead to use some ORM tool, that automates many of data access tasks. Though, I would say that CDB is more suited for reporting functionality or for CRUD over object model with simple relations -- exactly the case for the project you are describing, as far as I understand... so no objections here :)


5. Yakov Fain left...
Friday, 3 April 2009 6:47 pm

Valery, your arguments are poor.

1. No I don't. I'm passing to the client a collection of strongly typed Java DTO that get's serialized and gets automatically recreated as a set of AS3 objects. Why would I need to roll out any mapping layer?

2. JDBC is mandane, but we do use Clear Data Buildr that generates JDBC automatically.

3. I work with people who are not scared of SQL. Moreover, Hibernate will never write you as optimized code as a programmer with a decent knowledge of SQL.

People talk about some teams that don't have people who know SQL. Get rid of these people and hire decent programmers. Thanks to crisis, lots of good people are looking for work.


6. Valery left...
Friday, 3 April 2009 7:18 pm

Yakov,

You are comparing Clear Data Builder vs Hibernate, not a plain JDBC vs Hibernate. This is a big difference, I mentioned this already -- one ORM tool is probably more suitable for a task than another, no doubts here, but plain JDBC is a bad choice.

Regarding (1) -- "No I don't. I'm passing to the client a collection of strongly typed Java DTO that get's serialized and gets automatically recreated as a set of AS3 objects"

Yakov, you have to create that collection of DTO-s from java.sql.ResultSet first, this is what I were called "mapping layer". You can't bypass this step, simply CDB do it good enough.

Regarding (3) -- people who are not scared of SQL are not always SQL gurus, and this scares me. Like if I'm a passenger of a first-day pilot who is not scared about the flight :) And naive tricks of such gurus (like comma-separated multiple values in single column, or dot-encoded hierarchy path in single column, or 50+ columns per table to support 50+ translations) ruined performance of many applications. And they never called themselves dumb, they are definitely smarties, but Relation model is soooo limiting... )))

Yakov, I do not agree with your claim about non-optimized code generated by Hibernate. From my own experience it generates very descend code if designer of object model has a good understanding of 3 things: inheritance vs aggregation; aggregation vs association; lazy vs eager loading. 2 of them are fundamental OOD decisions, so if architect can't make correct decisions of those 2 types, then it's not a Hibernate fault.


7. Yakov Fain left...
Friday, 3 April 2009 7:27 pm

Not buying this answer either.

Let me ask an easier question. In which case would you say to a team of programmers, "Guys, you don't need to use Hibernate. Stick to JDBC/SQL"?


8. Valery left...
Friday, 3 April 2009 7:40 pm

Yakov,

You replied in such form, like if I stated that Hibernate is the only ORM tool. No, it's a matter of personal preference, but what I would like to say is that any good ORM tool is better than direct JDBC/SQL coding.

So, "Guys, you don't need to use _any ORM__. Stick to JDBC/SQL" if: 1. You do bulk import/export operations. ORM tools can do this as well, but there is no real benefits of using such tool (and no drawbacks either, though). 2. You do some DB transformations/migrations from one format to another. This is similar to (1), but it's better to use DB specific tools whenever possible -- they are way more simple and a bit more performant, Microsoft DTS coems to mind for ex. 3. You are developing your own ORM )))


9. Yakov Fain left...
Sunday, 5 April 2009 6:57 am

Imaging you have a team of strong Java developers and, say an Oracle person with excellent SQL skills. Would you recommend for a Web application a this architecture: a servlet container, JOTM and possibly MOM if need be?

If not, why?


10. Seeking left...
Tuesday, 22 December 2009 4:36 pm

Valery has some good arguments and offered a wonderful contribution to the discussion. It's too bad that you did not respond to her points directly, rather engaging her in a semi-confrontational manner, as she likely would have continued to participate. This would have allowed users like myself who ended up on this page to further benefit from the exchange.