HiShort comment on the cayenne sorted queries, they work great but be aware of a limitation:
(the query examples assume one to many relation Artist-Painting)
SelectQuery query = new SelectQuery(Painting.class); query.addOrdering(Painting.ARTIST_PROPERTY+"."+Artist.LAST_NAME,true);will not return the Paintings without artist. This behaviour is correct 90% of the times, but would be awesome if it could be controlled and customized so the null in the order path does not alter the results.
also be aware that a query for a relationship existence (or non- existence) does not work: SelectQuery query = new SelectQuery(Painting.class, ExpressionFactory.matchExp(Painting.ARTIST_PROPERTY, null)); so you might need a flag to indicate whether the relationship is set or not to allow easy querying and/or sorting.
If someone has a (simple) workaround to the problems I mentioned please share!
Cheers Marcin On 29/02/2008, at 8:03 AM, Marek Wawrzyczny wrote:
Thanks Kevin,Your response was quite encouraging. Most of the pages are very simple but there is one or two which enforces quite coplex workflow. It's a perfectcandidate for a child context. Just out of curiosity, how do people manage contexts in a typical CRUDapplication containing several (>10) entities. We're also using AJAX calls(DWR).Regarding queries. Hibernate often handles lazy initialized relationships very badly. There are two bugs I've hit where both HSQL and the Criteria API (kind of like the query builder API in Cayenne) have trouble creating the SQLquery. Take the following two entities: Course name classes Cllass course startsOn endsOnHibernate could potentially have trouble building a query that would return courses where we discrimante on both startsOn and endsOn properties of aClass.An additional bug may prevent ordering on either startsOn or endsOn if theproperty was used in the query.The issue is with the way Hibernate aliases the joins in the resultset.Obviously, I'd want to avoid that in the future. Cheers, Marek Wawrzyczny On Thu, 28 Feb 2008 00:51:59 Kevin Menard wrote:Hi Marek,My Hibernate experience is limited to a single project that did not useSpring, so it's hard for me to draw a fair comparison. My take frompassively watching on discussion lists (particularly the Tapestry one)is that Spring makes Hibernate usable in a way that Cayenne is out of the box. It seems you know this already, though.In a Web app I have here, we an account creation operation split up over three screens and it involves several different entities. For this, I simply used a peer context per page and coalesce everything at the end. This is a little bit older code and I would likely use a child context for it now. The reason I did it this way is that while conceptually asingle operation, completing any of the phases is a completetransaction. If you want to enforce start to finish behavior, you coulduse a single context shared via session. Just watch yourself because it's a lot harder to enforce a workflow through a browser than it is through Swing. As for sorting across multiple relationships, I guess I would have tounderstand a little more as to what you want to do. Simplest thing isto write your own Comparator, but you may want to look at mapping aquery, and barring that, use SQLTemplate to achieve what you need in theDB. I hope that helps.
smime.p7s
Description: S/MIME cryptographic signature
