You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Brian Burridge <ma...@burridge.net> on 2005/01/17 19:26:44 UTC

Using business objects instead of XML

Sorry if this is a very basic question. I have a several months
experience with Cocoon, but I've only done XML pipeline work. I'm
wondering how Cocoon can be used, if you are going to be using business
objects from the DB, for example Hibernate. I have seen the Wiki on
integrating Hibernate (and that's not my question). My question is how
does cocoon work with Business Objects since Cocoon seems to be based on
xml.

Do you convert the business objects to XML first? It seems like if you
don't, and you just create the business objects and use them via a JSP
page with JSTL or tags, then you are losing all the benefits of Cocoon.

Brian


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Using business objects instead of XML

Posted by Mark Lundquist <ml...@wrinkledog.com>.
On Jan 17, 2005, at 10:26 AM, Brian Burridge wrote:

> Sorry if this is a very basic question. I have a several months
> experience with Cocoon, but I've only done XML pipeline work. I'm
> wondering how Cocoon can be used, if you are going to be using business
> objects from the DB, for example Hibernate. I have seen the Wiki on
> integrating Hibernate (and that's not my question). My question is how
> does cocoon work with Business Objects since Cocoon seems to be based 
> on
> xml.
>
> Do you convert the business objects to XML first?

Yep.  Trivially done in the sitemap + flowsrcipt:

In the sitemap:

	<match pattern="page">
		<generate src="module:flow-attr:bizObject" />

In the flowscript:

	cocoon.sendPage ("page", bizObject);

> It seems like if you
> don't, and you just create the business objects and use them via a JSP
> page with JSTL or tags, then you are losing all the benefits of Cocoon.

:-)

HTH,
-ml-


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Using business objects instead of XML

Posted by Ugo Cei <ug...@apache.org>.
Il giorno 17/gen/05, alle 20:11, Brian Burridge ha scritto:

> Where do I put the code to get the Hibernate objects? Right now, with
> the GUI framework they have, its done in a Struts action, which then
> forwards to a JSP page and uses struts tags to display the contents of
> the objects.

You can do it in the flowscript or in an action. Personally, I prefer 
to use the flowscript.

	Ugo

-- 
Ugo Cei - http://beblogging.com/blojsom/blog/

Re: Using business objects instead of XML

Posted by Brian Burridge <ma...@burridge.net>.
I didn't mention Spring because I didn't want to complicate things yet,
but yes Spring will be used and already is (just not from within
Cocoon). I'll check that link you sent. Thanks.

Brian

On Mon, 2005-01-17 at 16:25, Mark Lundquist wrote:
> On Jan 17, 2005, at 11:11 AM, Brian Burridge wrote:
> 
> >
> > Where do I put the code to get the Hibernate objects? Right now, with
> > the GUI framework they have, its done in a Struts action, which then
> > forwards to a JSP page and uses struts tags to display the contents of
> > the objects.
> 
> If you implement your model in Java, then you get to use the Spring 
> framework w/ Hibernate.  Follow the instructions at 
> http://new.cocoondev.org/main/117/43.html and study that example!  Many 
> consider using Spring in this way to be the best practice for the 
> Cocoon+Hibernate combo.
> 
> If you don't do it that way, then you pretty much have to invoke the 
> Hibernate code from the flowscript.  You're going to open a Session and 
> start a Transaction, do some Hibernate stuff, etc.,  call sendPage(), 
> then end the Transaction and close Session.
> 
> The method to load the persistent object doesn't have to be called 
> directly in flow; you can call it from down in your model layer, but 
> then you have to pass the session down, too -- or, better: use the 
> Thread Local Session pattern (http://www.hibernate.org/42.html) (that's 
> what I would do if I weren't going to use the Spring+Hibernate stuff).
> 
> But the transaction and session have to enclose everything.  Don't make 
> the mistake of trying to bury all the hibernate stuff down in the model 
> layer (without using Spring, that is :-)... otherwise you get into 
> trouble with lazy initialization, e.g.
> 
> 1) flow calls method in model layer;
> 2) model opens session, does Hibernate stuff, closes session, returns 
> an object
> 3) flow calls sendPage();
> 4) Splaaat!  Hibernate says, "session closed or no session"
> 
> This kind of misdesign can result in kludgy workarounds.
> 
> GL, :-)
> -ml-
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Using business objects instead of XML

Posted by Mark Lundquist <ml...@wrinkledog.com>.
On Jan 17, 2005, at 11:11 AM, Brian Burridge wrote:

>
> Where do I put the code to get the Hibernate objects? Right now, with
> the GUI framework they have, its done in a Struts action, which then
> forwards to a JSP page and uses struts tags to display the contents of
> the objects.

If you implement your model in Java, then you get to use the Spring 
framework w/ Hibernate.  Follow the instructions at 
http://new.cocoondev.org/main/117/43.html and study that example!  Many 
consider using Spring in this way to be the best practice for the 
Cocoon+Hibernate combo.

If you don't do it that way, then you pretty much have to invoke the 
Hibernate code from the flowscript.  You're going to open a Session and 
start a Transaction, do some Hibernate stuff, etc.,  call sendPage(), 
then end the Transaction and close Session.

The method to load the persistent object doesn't have to be called 
directly in flow; you can call it from down in your model layer, but 
then you have to pass the session down, too -- or, better: use the 
Thread Local Session pattern (http://www.hibernate.org/42.html) (that's 
what I would do if I weren't going to use the Spring+Hibernate stuff).

But the transaction and session have to enclose everything.  Don't make 
the mistake of trying to bury all the hibernate stuff down in the model 
layer (without using Spring, that is :-)... otherwise you get into 
trouble with lazy initialization, e.g.

1) flow calls method in model layer;
2) model opens session, does Hibernate stuff, closes session, returns 
an object
3) flow calls sendPage();
4) Splaaat!  Hibernate says, "session closed or no session"

This kind of misdesign can result in kludgy workarounds.

GL, :-)
-ml-


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Using business objects instead of XML

Posted by Mark Lundquist <ml...@wrinkledog.com>.
On Jan 17, 2005, at 12:32 PM, Adam Ratcliffe wrote:

> Building on Mark's code snippets, if bizObject was an instance of a
> persistable object
> you would retrieve it using a Java class that created Hibernate 
> sessions,
> this class should
> implement the appropriate Avalon lifecycle interfaces so that it can be
> managed by the
> Cocoon component manager.

Or if that's overkill, you can use a POJO.
-ml-


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: Using business objects instead of XML

Posted by Adam Ratcliffe <ad...@mrigitech.com>.
> This point is moot. Hibernate can use Apache DBCP or a pooled 
> DataSource provided by your container, there's no reason to use either 
> Hibernate's pooling or Excalibur's.

Thanks for clarifying this point Ugo.

Cheers
Adam

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Using business objects instead of XML

Posted by Ugo Cei <ug...@apache.org>.
Il giorno 17/gen/05, alle 22:30, Adam Ratcliffe ha scritto:

> - use of Cocoon's connection pooling rather than the hibernate pooling
> which is not recommended for production use.

This point is moot. Hibernate can use Apache DBCP or a pooled 
DataSource provided by your container, there's no reason to use either 
Hibernate's pooling or Excalibur's.


-- 
Ugo Cei - http://beblogging.com/blojsom/blog/

RE: Using business objects instead of XML

Posted by Adam Ratcliffe <ad...@mrigitech.com>.
Hi Uzo

The important points in integrating hibernate with seem to be:

- use of Cocoon's connection pooling rather than the hibernate pooling
which is not recommended for production use.
- use of a servlet filter for closing the hibernate session, essential if
you're
using lazy intitialization of your hibernate objects and passing these to
pipelines
for processing

Both of these issues are described in more detail in the wiki document I
referenced
in the previous post.

Some people are now using the Spring framework for hibernate support, I
haven't tried
this myself, see http://new.cocoondev.org/main/117/43.html

Cheers
Adam

-----Original Message-----
From: beyaRecords [mailto:uzo@beyarecords.com]
Sent: Tuesday, 18 January 2005 10:00 a.m.
To: users@cocoon.apache.org
Subject: Re: Using business objects instead of XML



On 17 Jan 2005, at 20:32, Adam Ratcliffe wrote:

> var factory =
> cocoon.getComponent(Packages.org.test.PersistenceFactory.ROLE);
>
> You could then get your bizData like this:
>
> var hs = factory.createSession();
>
> var bizData = hs.find("from org.test.Data");

Adam,
never thought to do it this way, as I leave all the instantiation
within the hibernate class itself. Is it more efficient to do it this
way?

Uzo


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Using business objects instead of XML

Posted by beyaRecords <uz...@beyarecords.com>.
On 17 Jan 2005, at 20:32, Adam Ratcliffe wrote:

> var factory =
> cocoon.getComponent(Packages.org.test.PersistenceFactory.ROLE);
>
> You could then get your bizData like this:
>
> var hs = factory.createSession();
>
> var bizData = hs.find("from org.test.Data");

Adam,
never thought to do it this way, as I leave all the instantiation 
within the hibernate class itself. Is it more efficient to do it this 
way?

Uzo


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: Using business objects instead of XML

Posted by Adam Ratcliffe <ad...@mrigitech.com>.
Hi Brian,

Building on Mark's code snippets, if bizObject was an instance of a
persistable object
you would retrieve it using a Java class that created Hibernate sessions,
this class should
implement the appropriate Avalon lifecycle interfaces so that it can be
managed by the
Cocoon component manager.

The flow interpreter supports the use of Java classes directly in the
flowscript and using
an in-built function associated with the cocoon object you can get an
instance of your
hibernate component like this:

var factory =
cocoon.getComponent(Packages.org.test.PersistenceFactory.ROLE);

You could then get your bizData like this:

var hs = factory.createSession();

var bizData = hs.find("from org.test.Data");

See the wiki document
http://wiki.apache.org/cocoon/CocoonAndHibernateTutorial for a fuller
description of how to do this.

Cheers
Adam

-----Original Message-----
From: Brian Burridge [mailto:maillist@burridge.net]
Sent: Tuesday, 18 January 2005 8:12 a.m.
To: Cocoon Maillist
Subject: Re: Using business objects instead of XML


Using hibernate is what I want to find out about, because where I work
they already use hibernate.

Where do I put the code to get the Hibernate objects? Right now, with
the GUI framework they have, its done in a Struts action, which then
forwards to a JSP page and uses struts tags to display the contents of
the objects.

Brian

On Mon, 2005-01-17 at 13:33, beyaRecords wrote:
> On 17 Jan 2005, at 18:26, Brian Burridge wrote:
>
> > My question is how
> > does cocoon work with Bus
>
> I use cocoon with hibernate via flowscript/jx, but cocoon does have
> it's own persistence layer which you should look ivnto.
>
> regards
>
> Uzo
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Using business objects instead of XML

Posted by Brian Burridge <ma...@burridge.net>.
Using hibernate is what I want to find out about, because where I work
they already use hibernate.

Where do I put the code to get the Hibernate objects? Right now, with
the GUI framework they have, its done in a Struts action, which then
forwards to a JSP page and uses struts tags to display the contents of
the objects.

Brian

On Mon, 2005-01-17 at 13:33, beyaRecords wrote:
> On 17 Jan 2005, at 18:26, Brian Burridge wrote:
> 
> > My question is how
> > does cocoon work with Bus
> 
> I use cocoon with hibernate via flowscript/jx, but cocoon does have 
> it's own persistence layer which you should look ivnto.
> 
> regards
> 
> Uzo
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Using business objects instead of XML

Posted by beyaRecords <uz...@beyarecords.com>.
On 17 Jan 2005, at 18:26, Brian Burridge wrote:

> My question is how
> does cocoon work with Bus

I use cocoon with hibernate via flowscript/jx, but cocoon does have 
it's own persistence layer which you should look ivnto.

regards

Uzo


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org