A quite blunt but good estimation here is the amount of data that is needed to execute your business routines. If you run them in Java in the middle tier, and you need half of your dataset in application server memory, it might be a better option to leave it where it is, in the database system on a (usually) separate machine.
Ask yourself if a particular module of your application functionality needs object-oriented domain models and the polymorphic features of Java (and, most likely, has higher chances for portability and reusability). You then have two options: write Java stored procedures (yes, that exists) or write a "normal" Java application using EJB session beans, interceptors and a plain Java object domain model.
The persistence aspect would be taken care off by Hibernate. Hibernate will try to optimize your data access patterns (it gives you the tools to do so), so that access to your database would still perform well, even if a good part of your business logic executes in the application tier. However, this design is much better suited for many small transactions, in a highly concurrent fashion. This is where the effects of lazy, eager, and other fetching optimizations comes into play, as well as any caching solution. In other words, Hibernate is the right tool if you couple highly polymorphic and collaborative domain object models with common online transaction processing operation.
If, on the other hand, you are working with functionality that could be better described as a batch operation or some kind of reporting, executing business logic close to the datastore might make more sense. This means you'll usually write stored procedures in PL/SQL. If you still remember SQLJ, you can also write stored procedures in Java with a custom JDK and wrappers, both provided by the DBMS vendor.
For reporting, Hibernate can make some optimizations and provides several convenience functions (projection in Hibernate's SQL dialect HQL, "read only" queries, dynamic instantiation of report objects).
Even with batch processing, Hibernate can take care of most situations if you really work in batches and don't overload your memory. However, it should be clear that in almost all cases you either _work_ in batches or you really better move your business logic closer to your database and live with PL/SQL (or whatever language your stored procedures are written in). Clearly, moving huge chunks of data (effectively "fetching too much" all the time) into your application tier has to be avoided for best performance. If really portability is your goal, ask yourself if your database management system (including the database and its data) or your application will live longer. In my experience, this can't be guessed by me or anyone else up-front.
P.S. Usually most > medium scale applications need both, OLTP and OLAP support. While it can keep up for a while, object/relational mapping is very likely never the right candidate for mass data operations (assuming we don't see some kind of "new" ORM, including real Java stored procedures and decent relational type systems in our database products). So, let's all wait for the next SQLJ.
_________________ JAVA PERSISTENCE WITH HIBERNATE http://jpwh.org Get the book, training, and consulting for your Hibernate team.
|