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 <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> wrote:
> > thanks all.
> >
> > Nick
> >
> > On 6/29/05, Michael Henderson <[EMAIL PROTECTED]> 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 <[EMAIL
> > > PROTECTED]> 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: [EMAIL PROTECTED]
> > > >For additional commands, e-mail: [EMAIL PROTECTED]
> > > >
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
> >
> > --
> > Nick
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
> --
> "The passion for destruction is also a creative passion!"
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]