You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Ray <ra...@yahoo.co.uk> on 2004/12/20 13:16:07 UTC

Advice on using OJB collections and Struts

Hi there ... :-)

I'm involved in a small project to convert from a
Hibernate backend, to OJB. 

The presentation tier uses Struts and JSTL to render
pages.

I was wondering how you OJB handles collections
attached to objects, that need to be rendered in the
JSP pages. For example, if I have an Order object that
contains a collection of OrderLines, and I want to
create a page to display the whole order, then what is
the bst way to handle this?

Is it best to copy the whole Order and OrderLines into
some kind of VO, and then send that to the page? Or do
you use the Hibernate approach of leaving the session
open for the whole request cycle, so that the JSTL on
the page, can access the collection directly from the
Order object?

Hope that makes sense ... :-)


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Advice on using OJB collections and Struts

Posted by Brian McCallister <br...@chariotsolutions.com>.
You don't need to expose the session upwards. A proxied collection in 
OJB is capable of obtaining a PersistenceBroker if the one used to 
initial obtain the instance with the collection has been closed.

The only possible hangup with this is that the work is done, typically, 
in a transaction, and if the proxy is de-referenced outside of that 
transaction there is the possibility of stale data. On the other hand, 
the the same thing holds true using hibernate with an open session and 
closed transaction, and if the data wasn't loaded into the proxy during 
the transaction, it certainly wasn't used as part of it =)

-Brian

On Dec 20, 2004, at 10:33 AM, Ray wrote:

> Thanks to everyone who replied.
>
> It seems I was thinking that it used the Hibernate
> approach, which requires exposing the session right up
> to the presentation layer. I imagine that OJB does the
> same thing ... only the developer doesn't have to
> worry about it.
>
> Seems I have a bit more reading to do before I make a
> start on the conversion, but at least it means we can
> keep much of the database objects the same as they are
> for Hibernte; we just have to change stuff below the
> service layer that returns these objects from the
> database.
>
> Great stuff! Can't wait to get started!
>
> Any good books on OJB, by the way?
> --- Brian McCallister <br...@chariotsolutions.com>
> wrote:
>
>> I'll second this one -- the best approach I know is
>> just to use the
>> domain model object as the thing the JSP renders.
>>
>> -Brian
>>
>> On Dec 20, 2004, at 7:36 AM, Edson Carlos Ericksson
>> Richter wrote:
>>
>>> I've used the OJB objects and collections
>> directly, since they *are*
>>> my VO.
>>> There is no need to maintain any kind of "open
>> session", even if you
>>> are using proxies (OJB will care about opening a
>> database session to
>>> load object on demand)... I never used OJB + EJB,
>> so I can' tell you
>>> how this could work in a distributed environment.
>>> But with JSP accessing local datasources, I had no
>> problems.
>>>
>>> Copying object to other objects/collections could
>> lead into unecessary
>>> overhead.
>>>
>>> I expect this helps.
>>>
>>> Edson Richter
>>>
>>>
>>> Ray escreveu:
>>>
>>>> Hi there ... :-)
>>>>
>>>> I'm involved in a small project to convert from a
>>>> Hibernate backend, to OJB.
>>>> The presentation tier uses Struts and JSTL to
>> render
>>>> pages.
>>>>
>>>> I was wondering how you OJB handles collections
>>>> attached to objects, that need to be rendered in
>> the
>>>> JSP pages. For example, if I have an Order object
>> that
>>>> contains a collection of OrderLines, and I want
>> to
>>>> create a page to display the whole order, then
>> what is
>>>> the bst way to handle this?
>>>>
>>>> Is it best to copy the whole Order and OrderLines
>> into
>>>> some kind of VO, and then send that to the page?
>> Or do
>>>> you use the Hibernate approach of leaving the
>> session
>>>> open for the whole request cycle, so that the
>> JSTL on
>>>> the page, can access the collection directly from
>> the
>>>> Order object?
>>>>
>>>> Hope that makes sense ... :-)
>>>>
>>>>
>>>>
>> __________________________________________________
>>>> Do You Yahoo!?
>>>> Tired of spam?  Yahoo! Mail has the best spam
>> protection around
>>>> http://mail.yahoo.com
>>>>
>>
> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail:
>> ojb-user-unsubscribe@db.apache.org
>>>> For additional commands, e-mail:
>> ojb-user-help@db.apache.org
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>> -- 
>>> Edson Carlos Ericksson Richter
>>> MGR Informática Ltda.
>>> Fones: 3347-0446 / 9259-2993
>>>
>>>
>>>
>>
> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>> ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail:
>> ojb-user-help@db.apache.org
>>
>>
> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail:
>> ojb-user-help@db.apache.org
>>
>>
>
>
>
> 		
> __________________________________
> Do you Yahoo!?
> The all-new My Yahoo! - What will yours do?
> http://my.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Advice on using OJB collections and Struts

Posted by Ray <ra...@yahoo.co.uk>.
Thanks to everyone who replied.

It seems I was thinking that it used the Hibernate
approach, which requires exposing the session right up
to the presentation layer. I imagine that OJB does the
same thing ... only the developer doesn't have to
worry about it.

Seems I have a bit more reading to do before I make a
start on the conversion, but at least it means we can
keep much of the database objects the same as they are
for Hibernte; we just have to change stuff below the
service layer that returns these objects from the
database. 

Great stuff! Can't wait to get started!

Any good books on OJB, by the way?
--- Brian McCallister <br...@chariotsolutions.com>
wrote:

> I'll second this one -- the best approach I know is
> just to use the 
> domain model object as the thing the JSP renders.
> 
> -Brian
> 
> On Dec 20, 2004, at 7:36 AM, Edson Carlos Ericksson
> Richter wrote:
> 
> > I've used the OJB objects and collections
> directly, since they *are* 
> > my VO.
> > There is no need to maintain any kind of "open
> session", even if you 
> > are using proxies (OJB will care about opening a
> database session to 
> > load object on demand)... I never used OJB + EJB,
> so I can' tell you 
> > how this could work in a distributed environment.
> > But with JSP accessing local datasources, I had no
> problems.
> >
> > Copying object to other objects/collections could
> lead into unecessary 
> > overhead.
> >
> > I expect this helps.
> >
> > Edson Richter
> >
> >
> > Ray escreveu:
> >
> >> Hi there ... :-)
> >>
> >> I'm involved in a small project to convert from a
> >> Hibernate backend, to OJB.
> >> The presentation tier uses Struts and JSTL to
> render
> >> pages.
> >>
> >> I was wondering how you OJB handles collections
> >> attached to objects, that need to be rendered in
> the
> >> JSP pages. For example, if I have an Order object
> that
> >> contains a collection of OrderLines, and I want
> to
> >> create a page to display the whole order, then
> what is
> >> the bst way to handle this?
> >>
> >> Is it best to copy the whole Order and OrderLines
> into
> >> some kind of VO, and then send that to the page?
> Or do
> >> you use the Hibernate approach of leaving the
> session
> >> open for the whole request cycle, so that the
> JSTL on
> >> the page, can access the collection directly from
> the
> >> Order object?
> >>
> >> Hope that makes sense ... :-)
> >>
> >>
> >>
> __________________________________________________
> >> Do You Yahoo!?
> >> Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> >> http://mail.yahoo.com
> >>
>
---------------------------------------------------------------------
> >> To unsubscribe, e-mail:
> ojb-user-unsubscribe@db.apache.org
> >> For additional commands, e-mail:
> ojb-user-help@db.apache.org
> >>
> >>
> >>
> >>
> >
> >
> > -- 
> > Edson Carlos Ericksson Richter
> > MGR Inform�tica Ltda.
> > Fones: 3347-0446 / 9259-2993
> >
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> ojb-user-unsubscribe@db.apache.org
> > For additional commands, e-mail:
> ojb-user-help@db.apache.org
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail:
> ojb-user-help@db.apache.org
> 
> 



		
__________________________________ 
Do you Yahoo!? 
The all-new My Yahoo! - What will yours do?
http://my.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


RE: Advice on using OJB collections and Struts

Posted by Daniel Perry <d....@netcase.co.uk>.
+1
Works a treat. Especially with proxied collections as they are only loaded
as they are read, so you can just use the object and it wont load the
collections, but as soon as you access one it will load it. As JSPs only
access the object as a bean via reflection, you can always replace it with
different beans /VOs at a later time if you need to, without any changes in
the jsp.

Daniel.

> -----Original Message-----
> From: Brian McCallister [mailto:brianm@chariotsolutions.com]
> Sent: 20 December 2004 13:47
> To: OJB Users List
> Subject: Re: Advice on using OJB collections and Struts
>
>
> I'll second this one -- the best approach I know is just to use the
> domain model object as the thing the JSP renders.
>
> -Brian
>
> On Dec 20, 2004, at 7:36 AM, Edson Carlos Ericksson Richter wrote:
>
> > I've used the OJB objects and collections directly, since they *are*
> > my VO.
> > There is no need to maintain any kind of "open session", even if you
> > are using proxies (OJB will care about opening a database session to
> > load object on demand)... I never used OJB + EJB, so I can' tell you
> > how this could work in a distributed environment.
> > But with JSP accessing local datasources, I had no problems.
> >
> > Copying object to other objects/collections could lead into unecessary
> > overhead.
> >
> > I expect this helps.
> >
> > Edson Richter
> >
> >
> > Ray escreveu:
> >
> >> Hi there ... :-)
> >>
> >> I'm involved in a small project to convert from a
> >> Hibernate backend, to OJB.
> >> The presentation tier uses Struts and JSTL to render
> >> pages.
> >>
> >> I was wondering how you OJB handles collections
> >> attached to objects, that need to be rendered in the
> >> JSP pages. For example, if I have an Order object that
> >> contains a collection of OrderLines, and I want to
> >> create a page to display the whole order, then what is
> >> the bst way to handle this?
> >>
> >> Is it best to copy the whole Order and OrderLines into
> >> some kind of VO, and then send that to the page? Or do
> >> you use the Hibernate approach of leaving the session
> >> open for the whole request cycle, so that the JSTL on
> >> the page, can access the collection directly from the
> >> Order object?
> >>
> >> Hope that makes sense ... :-)
> >>
> >>
> >> __________________________________________________
> >> Do You Yahoo!?
> >> Tired of spam?  Yahoo! Mail has the best spam protection around
> >> http://mail.yahoo.com
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> >> For additional commands, e-mail: ojb-user-help@db.apache.org
> >>
> >>
> >>
> >>
> >
> >
> > --
> > Edson Carlos Ericksson Richter
> > MGR Informática Ltda.
> > Fones: 3347-0446 / 9259-2993
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> > For additional commands, e-mail: ojb-user-help@db.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Advice on using OJB collections and Struts

Posted by Brian McCallister <br...@chariotsolutions.com>.
I'll second this one -- the best approach I know is just to use the 
domain model object as the thing the JSP renders.

-Brian

On Dec 20, 2004, at 7:36 AM, Edson Carlos Ericksson Richter wrote:

> I've used the OJB objects and collections directly, since they *are* 
> my VO.
> There is no need to maintain any kind of "open session", even if you 
> are using proxies (OJB will care about opening a database session to 
> load object on demand)... I never used OJB + EJB, so I can' tell you 
> how this could work in a distributed environment.
> But with JSP accessing local datasources, I had no problems.
>
> Copying object to other objects/collections could lead into unecessary 
> overhead.
>
> I expect this helps.
>
> Edson Richter
>
>
> Ray escreveu:
>
>> Hi there ... :-)
>>
>> I'm involved in a small project to convert from a
>> Hibernate backend, to OJB.
>> The presentation tier uses Struts and JSTL to render
>> pages.
>>
>> I was wondering how you OJB handles collections
>> attached to objects, that need to be rendered in the
>> JSP pages. For example, if I have an Order object that
>> contains a collection of OrderLines, and I want to
>> create a page to display the whole order, then what is
>> the bst way to handle this?
>>
>> Is it best to copy the whole Order and OrderLines into
>> some kind of VO, and then send that to the page? Or do
>> you use the Hibernate approach of leaving the session
>> open for the whole request cycle, so that the JSTL on
>> the page, can access the collection directly from the
>> Order object?
>>
>> Hope that makes sense ... :-)
>>
>>
>> __________________________________________________
>> Do You Yahoo!?
>> Tired of spam?  Yahoo! Mail has the best spam protection around 
>> http://mail.yahoo.com
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>>
>>
>
>
> -- 
> Edson Carlos Ericksson Richter
> MGR Informática Ltda.
> Fones: 3347-0446 / 9259-2993
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Advice on using OJB collections and Struts

Posted by Edson Carlos Ericksson Richter <ed...@mgrinformatica.com.br>.
I've used the OJB objects and collections directly, since they *are* my VO.
There is no need to maintain any kind of "open session", even if you are 
using proxies (OJB will care about opening a database session to load 
object on demand)... I never used OJB + EJB, so I can' tell you how this 
could work in a distributed environment.
But with JSP accessing local datasources, I had no problems.

Copying object to other objects/collections could lead into unecessary 
overhead.

I expect this helps.

Edson Richter


Ray escreveu:

>Hi there ... :-)
>
>I'm involved in a small project to convert from a
>Hibernate backend, to OJB. 
>
>The presentation tier uses Struts and JSTL to render
>pages.
>
>I was wondering how you OJB handles collections
>attached to objects, that need to be rendered in the
>JSP pages. For example, if I have an Order object that
>contains a collection of OrderLines, and I want to
>create a page to display the whole order, then what is
>the bst way to handle this?
>
>Is it best to copy the whole Order and OrderLines into
>some kind of VO, and then send that to the page? Or do
>you use the Hibernate approach of leaving the session
>open for the whole request cycle, so that the JSTL on
>the page, can access the collection directly from the
>Order object?
>
>Hope that makes sense ... :-)
>
>
>__________________________________________________
>Do You Yahoo!?
>Tired of spam?  Yahoo! Mail has the best spam protection around 
>http://mail.yahoo.com 
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>
>  
>


-- 
Edson Carlos Ericksson Richter
MGR Informática Ltda.
Fones: 3347-0446 / 9259-2993