Reputation: 7779
I'm teaching Java EE, especially JPA, Spring and Spring MVC. As I have not so much experience in large projects, it is difficult to know what to present to students about optimisation of ORM.
At the present time, I present some classic optimisation tricks:
Is there any other point the community see about other way to optimize ORM ? I'm especially interested by DAO patterns...
Upvotes: 3
Views: 578
Reputation: 18379
For a set of JPA optimizations, and their resulting improvements, see,
http://java-persistence-performance.blogspot.com/2011/06/how-to-improve-jpa-performance-by-1825.html
Upvotes: 1
Reputation: 6678
From the point of developer, there are following optimization cases he must deal with:
So I can enlist few more optimizations:
All these cases fit under "write first, optimize later" rule (or "express intention first, optimize later").
Another well-known optimization-related API is prefetch API ("Prefetch paths"). The idea behind is to fetch a graph of objects that is expected to be processed further with minimal count of queries (or, better, in minimal time). So this API addresses "SELECT N+1" problem. Again, this part is normally expected to be implemented in any serious ORM product.
All above optimizations are safe from the point of transaction isolation - i.e. they don't break it. Caching-related optimizations normally aren't safe from this point: you must carefully configure caching to ensure you won't get stale objects when getting actual content is important (e.g. on security checks or on some real-time interaction). There are lots of techniques here, starting from usage of built-in caches in finishing with integration with distributed caches (memcached, etc.). Any approach solving the problem is good here; personally I would expect an open API allowing to integrate any with cache I prefer.
P.S. I'm a .NET fanboy, as well as one of DataObjects.Net and ORMeter.NET developers. So I don't know how exactly similar features are implemented in Java, but I'm familiar with the range of available solutions.
Upvotes: 5
Reputation: 5405
You mentioned the DAO pattern, but many in the JPA camp are saying the pattern is dead (I think the Hibernate guys have blogged on this, but I can't remember the link). Have a look at Spring Roo to see how they add the ORM-related functionality directly to the domain model via static methods.
Upvotes: 1
Reputation: 35741
Lazy-loading is via proxys is probably one of the killer features in ORM's.
Additionally, Hibernate is also able to proxy out requests like object.collection.count
and optimizes them, so instead of the whole collection being retrieved only a SELECT Count(*)
is issues.
Upvotes: 1
Reputation: 40679
Regarding Spring and Spring MVC, you might find this interesting. It's in C++, not Java, but it shows how to reduce UI source code w.r.t. Spring by an order of magnitude.
Upvotes: 1
Reputation: 54025
How about N+1 queries for collections? For example, see here: ORM Select n + 1 performance; join or no join
Upvotes: 1