You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Marek Wawrzyczny <ma...@internode.on.net> on 2008/02/26 13:13:44 UTC

Cayenne and Spring (a Hibernate inspired question)

Hi,

It has been a while since I last used Cayenne and that was within a Swing ROP 
context.

More recently I have been involved in writing a Spring MVC/Hibernate 
application. The experience has only made me fonder for Cayenne and now it 
appears that the team I'm in may consider ORM alternatives.

My application is relatively simple CRUD application with the exception of one 
set of two screens, where all data entry culminates in a parent/child 
interface (using Spring's AbstractWizardFormController ).

The object graph can become somewhat complex, combining objects from about 10 
different entities. The pages ideally would require a long-running session, 
or rather a ObjectContext spanning several requests.

I'm curious as to how well does Cayenne handle these types of interfaces in 
web applications.

The other problem we're currently having is sorting across multiple 
relationships.

I'm curious as to other people's experiences in this area. I would love to be 
able to convince the team to move to Cayenne if the framework fits the bill.


Kind regards,

Marek Wawrzyczny

Re: Cayenne and Spring (a Hibernate inspired question)

Posted by Malcolm Edgar <ma...@gmail.com>.
Another thing to consider is whether you want to serialize the object
graph in the session. Another approach is to write it to the database,
and have a status column in the parent object.  When the final page
"submit" is performed, the status column is flipped to invoke the
business process.

Using this design has some advantages in terms of scalability, and
user can come back to complete an application even if the session has
timed out, you can also see user abandonment of processes (i.e. where
did they get up to).  However with this pattern you need to have some
form of sweeper process to clean up abandoned applications, i.e. use a
Quartz job select all, pending status older than a configured period.

regards Malcolm Edgar
http://click.sourceforge.net

On Thu, Feb 28, 2008 at 2:15 AM, Michael Gentry <bl...@gmail.com> wrote:
> When I used Cayenne with a Tapestry application, I stored a
>  DataContext off in the session (so it was persistent across
>  request/response loops) and I could use it to handle objects I needed
>  to track from page-to-page (or even to the same page, but in a
>  different request/response loop).  This is what you are talking about,
>  I think, with "long-running session."  The only trickery I had to do
>  was tell Tapestry to stop serializing my Cayenne objects into the HTML
>  because on the next request/response loop, Tapestry would deserialize
>  those objects and you'd have a Cayenne object not attached to the
>  original DataContext.  Once I told Tapestry to leave Cayenne alone, it
>  worked much better for me.
>
>  Robert Ziegler showed how you can add sort orderings to your query.
>
>  /dev/mrg
>
>
>
>  On Tue, Feb 26, 2008 at 7:13 AM, Marek Wawrzyczny
>  <ma...@internode.on.net> wrote:
>  > Hi,
>  >
>  >  It has been a while since I last used Cayenne and that was within a Swing ROP
>  >  context.
>  >
>  >  More recently I have been involved in writing a Spring MVC/Hibernate
>  >  application. The experience has only made me fonder for Cayenne and now it
>  >  appears that the team I'm in may consider ORM alternatives.
>  >
>  >  My application is relatively simple CRUD application with the exception of one
>  >  set of two screens, where all data entry culminates in a parent/child
>  >  interface (using Spring's AbstractWizardFormController ).
>  >
>  >  The object graph can become somewhat complex, combining objects from about 10
>  >  different entities. The pages ideally would require a long-running session,
>  >  or rather a ObjectContext spanning several requests.
>  >
>  >  I'm curious as to how well does Cayenne handle these types of interfaces in
>  >  web applications.
>  >
>  >  The other problem we're currently having is sorting across multiple
>  >  relationships.
>  >
>  >  I'm curious as to other people's experiences in this area. I would love to be
>  >  able to convince the team to move to Cayenne if the framework fits the bill.
>  >
>  >
>  >  Kind regards,
>  >
>  >  Marek Wawrzyczny
>  >
>

Re: Cayenne and Spring (a Hibernate inspired question)

Posted by Michael Gentry <bl...@gmail.com>.
When I used Cayenne with a Tapestry application, I stored a
DataContext off in the session (so it was persistent across
request/response loops) and I could use it to handle objects I needed
to track from page-to-page (or even to the same page, but in a
different request/response loop).  This is what you are talking about,
I think, with "long-running session."  The only trickery I had to do
was tell Tapestry to stop serializing my Cayenne objects into the HTML
because on the next request/response loop, Tapestry would deserialize
those objects and you'd have a Cayenne object not attached to the
original DataContext.  Once I told Tapestry to leave Cayenne alone, it
worked much better for me.

Robert Ziegler showed how you can add sort orderings to your query.

/dev/mrg

On Tue, Feb 26, 2008 at 7:13 AM, Marek Wawrzyczny
<ma...@internode.on.net> wrote:
> Hi,
>
>  It has been a while since I last used Cayenne and that was within a Swing ROP
>  context.
>
>  More recently I have been involved in writing a Spring MVC/Hibernate
>  application. The experience has only made me fonder for Cayenne and now it
>  appears that the team I'm in may consider ORM alternatives.
>
>  My application is relatively simple CRUD application with the exception of one
>  set of two screens, where all data entry culminates in a parent/child
>  interface (using Spring's AbstractWizardFormController ).
>
>  The object graph can become somewhat complex, combining objects from about 10
>  different entities. The pages ideally would require a long-running session,
>  or rather a ObjectContext spanning several requests.
>
>  I'm curious as to how well does Cayenne handle these types of interfaces in
>  web applications.
>
>  The other problem we're currently having is sorting across multiple
>  relationships.
>
>  I'm curious as to other people's experiences in this area. I would love to be
>  able to convince the team to move to Cayenne if the framework fits the bill.
>
>
>  Kind regards,
>
>  Marek Wawrzyczny
>

Re: Cayenne and Spring (a Hibernate inspired question)

Posted by Robert Zeigler <ro...@puregumption.com>.
I've personally avoided Hibernate, so I can't speak to the spring/ 
hibernate stuff, sorry.

For sorting across multiple relationships, if you want to do it in- 
memory, you can always use cayenne's "Ordering".
You can add multiple orderings to any particular query, and you can  
also use multiple orderings on an in-memory list.
For example:

//sort an in-memory list of enrollments by the associated students'  
lastName then firstName
List<Ordering> orders = Arrays.asList(
	new Ordering("student.lastName",true),
	new Ordering("student.firstName",true));

Ordering.orderList(enrollments,orders);

//fetch a list of enrollments from the db, pre-ordered by the  
associated student lastname and firstname

SelectQuery query = new SelectQuery(Enrollment.class);
query.addOrdering("student.lastName",true);
query.addOrdering("student.firstName",true);

DataContext.getThreadDataContext().performQuery(query);

You can also create queries in the modeler tool, which supports adding  
multiple orderings.

HTH,

Robert


On Feb 27, 2008, at 2/277:51 AM , Kevin Menard wrote:

> Hi Marek,
>
> My Hibernate experience is limited to a single project that did not  
> use
> Spring, so it's hard for me to draw a fair comparison.  My take from
> passively 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 a
> single operation, completing any of the phases is a complete
> transaction.  If you want to enforce start to finish behavior, you  
> could
> use 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 to
> understand a little more as to what you want to do.  Simplest thing is
> to write your own Comparator, but you may want to look at mapping a
> query, and barring that, use SQLTemplate to achieve what you need in  
> the
> DB.
>
> I hope that helps.
>
> -- 
> Kevin Menard
> Servprise International, Inc.
> Remote reboot & power control for your network
> www.servprise.com                  +1 508.892.3823 x308
>
>
>> -----Original Message-----
>> From: Marek Wawrzyczny [mailto:marek_wawrzyczny@internode.on.net]
>> Sent: Tuesday, February 26, 2008 7:14 AM
>> To: user@cayenne.apache.org
>> Subject: Cayenne and Spring (a Hibernate inspired question)
>>
>> Hi,
>>
>> It has been a while since I last used Cayenne and that was within a
>> Swing ROP
>> context.
>>
>> More recently I have been involved in writing a Spring MVC/Hibernate
>> application. The experience has only made me fonder for Cayenne and
> now
>> it
>> appears that the team I'm in may consider ORM alternatives.
>>
>> My application is relatively simple CRUD application with the
> exception
>> of one
>> set of two screens, where all data entry culminates in a parent/child
>> interface (using Spring's AbstractWizardFormController ).
>>
>> The object graph can become somewhat complex, combining objects from
>> about 10
>> different entities. The pages ideally would require a long-running
>> session,
>> or rather a ObjectContext spanning several requests.
>>
>> I'm curious as to how well does Cayenne handle these types of
>> interfaces in
>> web applications.
>>
>> The other problem we're currently having is sorting across multiple
>> relationships.
>>
>> I'm curious as to other people's experiences in this area. I would
> love
>> to be
>> able to convince the team to move to Cayenne if the framework fits  
>> the
>> bill.
>>
>>
>> Kind regards,
>>
>> Marek Wawrzyczny


Re: Cayenne and Spring (a Hibernate inspired question)

Posted by Andrus Adamchik <an...@objectstyle.org>.
It should work... Just to be sure I tried it on MySQL 5. It works:

1. One-to-many OUTER JOIN:

mysql> select t0.artist_id, t1.painting_title  FROM artist t0 left  
join painting t1 on t0.artist_id = t1.artist_id order by  
t1.PAINTING_TITLE;
+-----------+----------------+
| artist_id | painting_title |
+-----------+----------------+
|         2 | NULL           |
|         1 | ABAAC          |
|         1 | ADDDD          |
|         1 | BBDDDD         |
|         1 | BDDDD          |
+-----------+----------------+


2. Many to one OUTER JOIN:

mysql> select t0.painting_id, t1.artist_name FROM painting t0 left  
join artist t1 on t0.artist_id = t1.artist_id  order by t1.artist_name;
+-------------+-------------+
| painting_id | artist_name |
+-------------+-------------+
|       33005 | NULL        |
|       33001 | X           |
|       33002 | X           |
|       33003 | X           |
|       33004 | X           |
+-------------+-------------+


Andrus



On Feb 28, 2008, at 3:15 PM, Marek Wawrzyczny wrote:
> Thanks Marcin and Andrus,
>
> Andrus, are you sure that the problem Marcin is describing can be  
> solved?
>
> I thought that something like:
>
> SELECT t1.id, t1.a, t1.t2_fk, t2.id, t2.x
> FROM table1 AS t1
> LEFT JOIN table2 AS t2 ON t2.id = t1.t2_fk
> ORDER BY t2.x
>
> would never return results from t1 that do not have a related t2  
> record. Of
> course it's been a while since SQL theory lectures :)
>
> Cheers,
>
> Marek Wawrzyczny
>
>
> On Thu, 28 Feb 2008 23:56:07 Andrus Adamchik wrote:
>> 3.0 EJBQLQuery should be able to handle that.
>>
>> Andrus
>>
>> On Feb 28, 2008, at 2:44 PM, Marcin Skladaniec wrote:
>>> Hi
>>>
>>> Short 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
>>>> perfect
>>>> candidate for a child context.
>>>>
>>>> Just out of curiosity, how do people manage contexts in a typical
>>>> CRUD
>>>> application 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
>>>> SQL
>>>> query. Take the following two entities:
>>>>
>>>> Course
>>>> name
>>>> classes
>>>>
>>>> Cllass
>>>> course
>>>> startsOn
>>>> endsOn
>>>>
>>>> Hibernate could potentially have trouble building a query that
>>>> would return
>>>> courses where we discrimante on both startsOn and endsOn properties
>>>> of a
>>>> Class.
>>>>
>>>> An additional bug may prevent ordering on either startsOn or
>>>> endsOn  if the
>>>> property 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 use
>>>>> Spring, so it's hard for me to draw a fair comparison.  My take  
>>>>> from
>>>>> passively 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 a
>>>>> single operation, completing any of the phases is a complete
>>>>> transaction.  If you want to enforce start to finish behavior, you
>>>>> could
>>>>> use 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
>>>>> to
>>>>> understand a little more as to what you want to do.  Simplest
>>>>> thing is
>>>>> to write your own Comparator, but you may want to look at  
>>>>> mapping a
>>>>> query, and barring that, use SQLTemplate to achieve what you need
>>>>> in the
>>>>> DB.
>>>>>
>>>>> I hope that helps.
>
>
>


Re: Cayenne and Spring (a Hibernate inspired question)

Posted by Marek Wawrzyczny <ma...@internode.on.net>.
Thanks Marcin and Andrus,

Andrus, are you sure that the problem Marcin is describing can be solved?

I thought that something like:

SELECT t1.id, t1.a, t1.t2_fk, t2.id, t2.x 
FROM table1 AS t1
LEFT JOIN table2 AS t2 ON t2.id = t1.t2_fk
ORDER BY t2.x

would never return results from t1 that do not have a related t2 record. Of 
course it's been a while since SQL theory lectures :)

Cheers,

Marek Wawrzyczny


On Thu, 28 Feb 2008 23:56:07 Andrus Adamchik wrote:
> 3.0 EJBQLQuery should be able to handle that.
>
> Andrus
>
> On Feb 28, 2008, at 2:44 PM, Marcin Skladaniec wrote:
> > Hi
> >
> > Short 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
> >> perfect
> >> candidate for a child context.
> >>
> >> Just out of curiosity, how do people manage contexts in a typical
> >> CRUD
> >> application 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
> >> SQL
> >> query. Take the following two entities:
> >>
> >> Course
> >> name
> >> classes
> >>
> >> Cllass
> >> course
> >> startsOn
> >> endsOn
> >>
> >> Hibernate could potentially have trouble building a query that
> >> would return
> >> courses where we discrimante on both startsOn and endsOn properties
> >> of a
> >> Class.
> >>
> >> An additional bug may prevent ordering on either startsOn or
> >> endsOn  if the
> >> property 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 use
> >>> Spring, so it's hard for me to draw a fair comparison.  My take from
> >>> passively 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 a
> >>> single operation, completing any of the phases is a complete
> >>> transaction.  If you want to enforce start to finish behavior, you
> >>> could
> >>> use 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
> >>> to
> >>> understand a little more as to what you want to do.  Simplest
> >>> thing is
> >>> to write your own Comparator, but you may want to look at mapping a
> >>> query, and barring that, use SQLTemplate to achieve what you need
> >>> in the
> >>> DB.
> >>>
> >>> I hope that helps.



Re: Cayenne and Spring (a Hibernate inspired question)

Posted by Andrus Adamchik <an...@objectstyle.org>.
3.0 EJBQLQuery should be able to handle that.

Andrus


On Feb 28, 2008, at 2:44 PM, Marcin Skladaniec wrote:

> Hi
>
> Short 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  
>> perfect
>> candidate for a child context.
>>
>> Just out of curiosity, how do people manage contexts in a typical  
>> CRUD
>> application 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  
>> SQL
>> query. Take the following two entities:
>>
>> Course
>> name
>> classes
>>
>> Cllass
>> course
>> startsOn
>> endsOn
>>
>> Hibernate could potentially have trouble building a query that  
>> would return
>> courses where we discrimante on both startsOn and endsOn properties  
>> of a
>> Class.
>>
>> An additional bug may prevent ordering on either startsOn or  
>> endsOn  if the
>> property 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 use
>>> Spring, so it's hard for me to draw a fair comparison.  My take from
>>> passively 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 a
>>> single operation, completing any of the phases is a complete
>>> transaction.  If you want to enforce start to finish behavior, you  
>>> could
>>> use 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  
>>> to
>>> understand a little more as to what you want to do.  Simplest  
>>> thing is
>>> to write your own Comparator, but you may want to look at mapping a
>>> query, and barring that, use SQLTemplate to achieve what you need  
>>> in the
>>> DB.
>>>
>>> I hope that helps.
>>
>>
>


Re: Cayenne and Spring (a Hibernate inspired question)

Posted by Marcin Skladaniec <ma...@ish.com.au>.
Hi

Short 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  
> perfect
> candidate for a child context.
>
> Just out of curiosity, how do people manage contexts in a typical CRUD
> application 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  
> SQL
> query. Take the following two entities:
>
> Course
> name
> classes
>
> Cllass
>  course
> startsOn
> endsOn
>
> Hibernate could potentially have trouble building a query that would  
> return
> courses where we discrimante on both startsOn and endsOn properties  
> of a
> Class.
>
> An additional bug may prevent ordering on either startsOn or endsOn   
> if the
> property 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  
>> use
>> Spring, so it's hard for me to draw a fair comparison.  My take from
>> passively 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 a
>> single operation, completing any of the phases is a complete
>> transaction.  If you want to enforce start to finish behavior, you  
>> could
>> use 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 to
>> understand a little more as to what you want to do.  Simplest thing  
>> is
>> to write your own Comparator, but you may want to look at mapping a
>> query, and barring that, use SQLTemplate to achieve what you need  
>> in the
>> DB.
>>
>> I hope that helps.
>
>


Re: Cayenne and Spring (a Hibernate inspired question)

Posted by Michael Gentry <bl...@gmail.com>.
It is my experience that Cayenne handles lazy relationships (faults)
very well -- just keep your objects/data context/etc around.  As soon
as a fault is triggered, Cayenne will get a (pooled) connection to the
database, do what it needs, then return the connection.  When I was
subscribed to the Tapestry mailing list, that question would literally
arise every 1-3 weeks with people thinking it was a Tapestry problem
when in fact it is a Hibernate problem.  (I recently attended a
Hibernate training class and that was one of the topics.)  In my
Tapestry+Cayenne application it was never an issue and it was abusive
on lazy relationships.  The only thing I had to overcome was Tapestry
4 serializing my CayenneDataObjects to the HTML as hidden fields.
Once I figured that out, it worked fine.

/dev/mrg

On Thu, Feb 28, 2008 at 5:03 PM, Marek Wawrzyczny
<ma...@internode.on.net> wrote:
>  Regarding queries. Hibernate often handles lazy initialized relationships very
>  badly.

Re: Cayenne and Spring (a Hibernate inspired question)

Posted by Marek Wawrzyczny <ma...@internode.on.net>.
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 perfect 
candidate for a child context.

Just out of curiosity, how do people manage contexts in a typical CRUD 
application 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 SQL 
query. Take the following two entities:

Course
 name
 classes

Cllass
  course
 startsOn
 endsOn

Hibernate could potentially have trouble building a query that would return 
courses where we discrimante on both startsOn and endsOn properties of a 
Class.

An additional bug may prevent ordering on either startsOn or endsOn  if the 
property 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 use
> Spring, so it's hard for me to draw a fair comparison.  My take from
> passively 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 a
> single operation, completing any of the phases is a complete
> transaction.  If you want to enforce start to finish behavior, you could
> use 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 to
> understand a little more as to what you want to do.  Simplest thing is
> to write your own Comparator, but you may want to look at mapping a
> query, and barring that, use SQLTemplate to achieve what you need in the
> DB.
>
> I hope that helps.



RE: Cayenne and Spring (a Hibernate inspired question)

Posted by Kevin Menard <km...@servprise.com>.
Hi Marek,

My Hibernate experience is limited to a single project that did not use
Spring, so it's hard for me to draw a fair comparison.  My take from
passively 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 a
single operation, completing any of the phases is a complete
transaction.  If you want to enforce start to finish behavior, you could
use 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 to
understand a little more as to what you want to do.  Simplest thing is
to write your own Comparator, but you may want to look at mapping a
query, and barring that, use SQLTemplate to achieve what you need in the
DB.

I hope that helps.

-- 
Kevin Menard
Servprise International, Inc.
Remote reboot & power control for your network
www.servprise.com                  +1 508.892.3823 x308


> -----Original Message-----
> From: Marek Wawrzyczny [mailto:marek_wawrzyczny@internode.on.net]
> Sent: Tuesday, February 26, 2008 7:14 AM
> To: user@cayenne.apache.org
> Subject: Cayenne and Spring (a Hibernate inspired question)
> 
> Hi,
> 
> It has been a while since I last used Cayenne and that was within a
> Swing ROP
> context.
> 
> More recently I have been involved in writing a Spring MVC/Hibernate
> application. The experience has only made me fonder for Cayenne and
now
> it
> appears that the team I'm in may consider ORM alternatives.
> 
> My application is relatively simple CRUD application with the
exception
> of one
> set of two screens, where all data entry culminates in a parent/child
> interface (using Spring's AbstractWizardFormController ).
> 
> The object graph can become somewhat complex, combining objects from
> about 10
> different entities. The pages ideally would require a long-running
> session,
> or rather a ObjectContext spanning several requests.
> 
> I'm curious as to how well does Cayenne handle these types of
> interfaces in
> web applications.
> 
> The other problem we're currently having is sorting across multiple
> relationships.
> 
> I'm curious as to other people's experiences in this area. I would
love
> to be
> able to convince the team to move to Cayenne if the framework fits the
> bill.
> 
> 
> Kind regards,
> 
> Marek Wawrzyczny