Investigating Cayenne

9/8/2006 - Marco (updated on 9/18/2020)

Cayenne has nice-looking modeling tools and a decent API, but has other interesting limitations in their prefetching

Here are a few things I noticed about the framework:

Their explanation of how many queries it takes to get a list of objects, each with 1-n sublink is confusing, at best. I expect it to take exactly one (1) query ... they say two? ... oh, Lord, check out the lovely syntax they have in the "advanced" section below:


Intuitive and beautiful.

  1. No aliased links ... programmer is advised to avoid this problem ... "To-many relationships should not be prefetched if a query qualifier can potentially reduce a number of related objects, resulting in incorrect relationship list." Transaction support is pretty unwieldy -- it's automatic in most cases, but the "best practices" code creating one on your own and handling it is unwieldy, at best:

try {
    // do something...
    // if no failures, commit
catch (Exception ex) {
finally {
    if (tx.getStatus() == Transaction.STATUS_MARKED_ROLLEDBACK) {
        try {
        catch (Exception rollbackEx) {

On the other hand, there is this:

Cayenne ensures that each ObjectContext contains at most one instance of each unique persistent object. In other words if two separate independent queries fetched a row with the same primary key, the same object instance will be used in both results. This behavior (not supported by some other frameworks), is extremely important in maintaining consistency of the object graph.

There is also a good page on Object Caching, which explains how objects synchronization is maintained across JVMs. The only line to cause some worry is this one: "Due to concurrency issues discussed above, if a snapshot version conflict occurs, DataRowStore removes a given snapshot from the cache to avoid dealing with concurrency effects on merging." Does this mean that data is lost?

Sign up for our Newsletter