You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Tapestry Stuff <ta...@gmail.com> on 2005/06/29 15:07:15 UTC
Best practices for Tapestry 3 + Spring + Hibernate
Hi, new guy around here.
Can anybody point me to a resource describing the canonical pattern
for integrating Spring with Tapestry 3? Hibernate is in use but
(correct me if I'm wrong) if one can work the Spring problem out then
Hibernate will be easy.
Also, planning on building components that use Spring beans - what is
the best way to inject beans into these components regardless of the
page they reside in?
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Best practices for Tapestry 3 + Spring + Hibernate
Posted by Vinicius Carvalho <ja...@gmail.com>.
I've used the one described on spring manual
Create a Base engine for you
Let's say SpringBaseEngine
public class SpringBaseEngine extends BaseEngine {
private static final long serialVersionUID = 3905241217045443380L;
public static final String APPLICATION_CONTEXT_KEY = "appContext";
protected void setupForRequest(RequestContext context) {
super.setupForRequest(context);
Map global = (Map) getGlobal();
ApplicationContext ac = (ApplicationContext)
global.get(APPLICATION_CONTEXT_KEY);
if (ac == null) {
ac = WebApplicationContextUtils.getWebApplicationContext(
context.getServlet().getServletContext()
);
global.put(APPLICATION_CONTEXT_KEY, ac);
}
}
}
define your engine for your application:
<application engine-class="com.mgjug.view.engine.SpringBaseEngine" >
You're almost there...
in your component :
<property-specification name="userService"
type="net.sf.webfeeds.services.service.user.UserService">
page.global.appContext.getBean("userService")
</property-specification>
Ok, it depends on your page, but which component isn't contained by one?
>From now on is pretty straightforward. Your services get your daos
injected as well other dependencies
I'm looking forward Tapestry + Hivemind. I'll give a shot next week
and post an example
Regards
On 6/29/05, Tapestry Stuff <ta...@gmail.com> wrote:
> Hi, new guy around here.
>
> Can anybody point me to a resource describing the canonical pattern
> for integrating Spring with Tapestry 3? Hibernate is in use but
> (correct me if I'm wrong) if one can work the Spring problem out then
> Hibernate will be easy.
>
> Also, planning on building components that use Spring beans - what is
> the best way to inject beans into these components regardless of the
> page they reside in?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Best practices for Tapestry 3 + Spring + Hibernate
Posted by Juan Esteban Maya <jm...@gmail.com>.
Ey, Nice. i like your approach!!!
But how can i use it to return Object collections?
On 6/29/05, Vinicius Carvalho <ja...@gmail.com> wrote:
> 2 approaches
>
> - OSVF (Open Session in View Filter), which I don't like (search google for it)
> - Have a better control on your objects. Example: If you need Item in
> a page, bring only item, if you need Item + Bids, bring Item + Bids.
> One way I do this:
>
> public Entity findByPrimaryKey(Serializable pk) throws PersistenceException {
> return findByPrimaryKey(pk,null);
> }
>
>
> public Entity findByPrimaryKey(Serializable pk, String[]
> initialize) throws PersistenceException{
> Session session = getCurrentSession();
> Entity entity = null;
> try {
> entity = (Entity) session.get(getEntityClass(), pk);
> entity = initialize(entity,initialize);
> } catch (HibernateException e) {
> logger.error(e);
> throw new PersistenceException(e);
> } finally {
> closeSession();
> }
> return entity;
>
> }
>
> private Entity initialize(Entity entity, String[] initialize){
> try{
> if(initialize != null){
> for(int i=0;i<initialize.length;i++){
> Hibernate.initialize(PropertyUtils.getProperty(entity,initialize[i]));
> }
> }
> }catch(Exception e){
> e.printStackTrace();
> }finally{
> closeSession();
> }
> return entity;
> }
>
>
> I hope the code speaks for it self.
> Im in a rush right now, I coudl give better examples later (if someone
> else doesn't)
>
> Cheers
>
> On 6/29/05, Juan Esteban Maya <jm...@gmail.com> wrote:
> > I have been trying to implement this also and the main problem that i
> > have found is the infamous "LazyLoadingException". Im still searching
> > for a 100% solution to this problem.
> >
> > If you also have this problem try the Wiki solution.
> > http://wiki.apache.org/jakarta-tapestry/FrequentlyAskedQuestions/SpringHibernate
> >
> >
> > On 6/29/05, Tapestry Stuff <ta...@gmail.com> wrote:
> > > thanks all.
> > >
> > > Nick
> > >
> > > On 6/29/05, Michael Henderson <mh...@mac.com> wrote:
> > > > Hi,
> > > > Subclass BaseEngine, over-ride setupForRequest(), store the context in global
> > > > and provide utility methods to get the spring context from the engine and the page
> > > >
> > > > google "tapestry spring hibernate example" or just download source from
> > > >
> > > > https://betterpetshop.dev.java.net/
> > > >
> > > > to get you started
> > > >
> > > > Mike
> > > >
> > > > On Wednesday, June 29, 2005, at 06:08AM, Tapestry Stuff <ta...@gmail.com> wrote:
> > > >
> > > > >Hi, new guy around here.
> > > > >
> > > > >Can anybody point me to a resource describing the canonical pattern
> > > > >for integrating Spring with Tapestry 3? Hibernate is in use but
> > > > >(correct me if I'm wrong) if one can work the Spring problem out then
> > > > >Hibernate will be easy.
> > > > >
> > > > >Also, planning on building components that use Spring beans - what is
> > > > >the best way to inject beans into these components regardless of the
> > > > >page they reside in?
> > > > >
> > > > >---------------------------------------------------------------------
> > > > >To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > > > >For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> > > > >
> > > > >
> > > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> > > >
> > > >
> > >
> > >
> > > --
> > > Nick
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> > >
> > >
> >
> >
> > --
> > "The passion for destruction is also a creative passion!"
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
>
--
"The passion for destruction is also a creative passion!"
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Best practices for Tapestry 3 + Spring + Hibernate
Posted by Vinicius Carvalho <ja...@gmail.com>.
2 approaches
- OSVF (Open Session in View Filter), which I don't like (search google for it)
- Have a better control on your objects. Example: If you need Item in
a page, bring only item, if you need Item + Bids, bring Item + Bids.
One way I do this:
public Entity findByPrimaryKey(Serializable pk) throws PersistenceException {
return findByPrimaryKey(pk,null);
}
public Entity findByPrimaryKey(Serializable pk, String[]
initialize) throws PersistenceException{
Session session = getCurrentSession();
Entity entity = null;
try {
entity = (Entity) session.get(getEntityClass(), pk);
entity = initialize(entity,initialize);
} catch (HibernateException e) {
logger.error(e);
throw new PersistenceException(e);
} finally {
closeSession();
}
return entity;
}
private Entity initialize(Entity entity, String[] initialize){
try{
if(initialize != null){
for(int i=0;i<initialize.length;i++){
Hibernate.initialize(PropertyUtils.getProperty(entity,initialize[i]));
}
}
}catch(Exception e){
e.printStackTrace();
}finally{
closeSession();
}
return entity;
}
I hope the code speaks for it self.
Im in a rush right now, I coudl give better examples later (if someone
else doesn't)
Cheers
On 6/29/05, Juan Esteban Maya <jm...@gmail.com> wrote:
> I have been trying to implement this also and the main problem that i
> have found is the infamous "LazyLoadingException". Im still searching
> for a 100% solution to this problem.
>
> If you also have this problem try the Wiki solution.
> http://wiki.apache.org/jakarta-tapestry/FrequentlyAskedQuestions/SpringHibernate
>
>
> On 6/29/05, Tapestry Stuff <ta...@gmail.com> wrote:
> > thanks all.
> >
> > Nick
> >
> > On 6/29/05, Michael Henderson <mh...@mac.com> wrote:
> > > Hi,
> > > Subclass BaseEngine, over-ride setupForRequest(), store the context in global
> > > and provide utility methods to get the spring context from the engine and the page
> > >
> > > google "tapestry spring hibernate example" or just download source from
> > >
> > > https://betterpetshop.dev.java.net/
> > >
> > > to get you started
> > >
> > > Mike
> > >
> > > On Wednesday, June 29, 2005, at 06:08AM, Tapestry Stuff <ta...@gmail.com> wrote:
> > >
> > > >Hi, new guy around here.
> > > >
> > > >Can anybody point me to a resource describing the canonical pattern
> > > >for integrating Spring with Tapestry 3? Hibernate is in use but
> > > >(correct me if I'm wrong) if one can work the Spring problem out then
> > > >Hibernate will be easy.
> > > >
> > > >Also, planning on building components that use Spring beans - what is
> > > >the best way to inject beans into these components regardless of the
> > > >page they reside in?
> > > >
> > > >---------------------------------------------------------------------
> > > >To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > > >For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> > > >
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> > >
> > >
> >
> >
> > --
> > Nick
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
>
>
> --
> "The passion for destruction is also a creative passion!"
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Best practices for Tapestry 3 + Spring + Hibernate
Posted by Juan Esteban Maya <jm...@gmail.com>.
I have been trying to implement this also and the main problem that i
have found is the infamous "LazyLoadingException". Im still searching
for a 100% solution to this problem.
If you also have this problem try the Wiki solution.
http://wiki.apache.org/jakarta-tapestry/FrequentlyAskedQuestions/SpringHibernate
On 6/29/05, Tapestry Stuff <ta...@gmail.com> wrote:
> thanks all.
>
> Nick
>
> On 6/29/05, Michael Henderson <mh...@mac.com> wrote:
> > Hi,
> > Subclass BaseEngine, over-ride setupForRequest(), store the context in global
> > and provide utility methods to get the spring context from the engine and the page
> >
> > google "tapestry spring hibernate example" or just download source from
> >
> > https://betterpetshop.dev.java.net/
> >
> > to get you started
> >
> > Mike
> >
> > On Wednesday, June 29, 2005, at 06:08AM, Tapestry Stuff <ta...@gmail.com> wrote:
> >
> > >Hi, new guy around here.
> > >
> > >Can anybody point me to a resource describing the canonical pattern
> > >for integrating Spring with Tapestry 3? Hibernate is in use but
> > >(correct me if I'm wrong) if one can work the Spring problem out then
> > >Hibernate will be easy.
> > >
> > >Also, planning on building components that use Spring beans - what is
> > >the best way to inject beans into these components regardless of the
> > >page they reside in?
> > >
> > >---------------------------------------------------------------------
> > >To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > >For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> > >
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
>
>
> --
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
--
"The passion for destruction is also a creative passion!"
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Best practices for Tapestry 3 + Spring + Hibernate
Posted by Tapestry Stuff <ta...@gmail.com>.
thanks all.
Nick
On 6/29/05, Michael Henderson <mh...@mac.com> wrote:
> Hi,
> Subclass BaseEngine, over-ride setupForRequest(), store the context in global
> and provide utility methods to get the spring context from the engine and the page
>
> google "tapestry spring hibernate example" or just download source from
>
> https://betterpetshop.dev.java.net/
>
> to get you started
>
> Mike
>
> On Wednesday, June 29, 2005, at 06:08AM, Tapestry Stuff <ta...@gmail.com> wrote:
>
> >Hi, new guy around here.
> >
> >Can anybody point me to a resource describing the canonical pattern
> >for integrating Spring with Tapestry 3? Hibernate is in use but
> >(correct me if I'm wrong) if one can work the Spring problem out then
> >Hibernate will be easy.
> >
> >Also, planning on building components that use Spring beans - what is
> >the best way to inject beans into these components regardless of the
> >page they reside in?
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
--
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Best practices for Tapestry 3 + Spring + Hibernate
Posted by Michael Henderson <mh...@mac.com>.
Hi,
Subclass BaseEngine, over-ride setupForRequest(), store the context in global
and provide utility methods to get the spring context from the engine and the page
google "tapestry spring hibernate example" or just download source from
https://betterpetshop.dev.java.net/
to get you started
Mike
On Wednesday, June 29, 2005, at 06:08AM, Tapestry Stuff <ta...@gmail.com> wrote:
>Hi, new guy around here.
>
>Can anybody point me to a resource describing the canonical pattern
>for integrating Spring with Tapestry 3? Hibernate is in use but
>(correct me if I'm wrong) if one can work the Spring problem out then
>Hibernate will be easy.
>
>Also, planning on building components that use Spring beans - what is
>the best way to inject beans into these components regardless of the
>page they reside in?
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org