RE: [newbie] Wicket, Spring, Hibernate and transactions in views.

2010-03-03 Thread Colin Rogers
James,

Thank you very much for that - a working example is exactly what I need! :)

Cheers,
Col.

-Original Message-
From: James Carman [mailto:jcar...@carmanconsulting.com] 
Sent: 02 March 2010 17:59
To: users@wicket.apache.org
Subject: Re: [newbie] Wicket, Spring, Hibernate and transactions in views.

Introduce AspectJ and spring-aspects into your build.  You can see an
example of it in my wicket-advanced sample project:

http://svn.carmanconsulting.com/public/wicket-advanced/trunk/

Then, AspectJ will weave the transaction support into your
Page/Component classes like you want.  There are limits on what type
of methods can be transactional, though.  I would also recommend the
OpenSessionInView filter (which my example project also uses).

On Tue, Mar 2, 2010 at 11:25 AM, Colin Rogers  wrote:
> All,
>
>
>
> I've got a bit of a newbie Wicket question involving Spring, Hibernate
> and transactions.
>
>
>
> The question that I can't seem to find an answer to;
>
>
>
> Can a view be a created/injected/aop'd like a spring bean so that it
> honours @Transactional methods for hibernate?
>
>
>
> An example;
>
>
>
> public class HomePage extends WebPage {
>
>
>
> @SpringBean // this is working fine
>
> private SessionFactory sessionFactory;
>
>
>
> public HomePage(final PageParameters parameters) {
>
>
>
> this.init();
>
>      }
>
>
>
>     �...@transactional // this is not working
>
>      public void init() {
>
>
>
>            Criteria criteria =
> sessionFactory.getCurrentSession().createCriteria(MyEntity.class);
>
>            List myEntities = criteria.list();
>
>            for( MyEntity myEntity : myEntities ) {
>
>
>
>                  // where subEntities is a lazy collection
>
>                  for( SubEntity subEntity : myEntity.getSubEntities() )
> {
>
>
>
>                        // ...
>
>                  }
>
>            }
>
> }
>
> }
>
>
>
> I've been reading Wicket In Action book, various places on the net and
> of course, emails on the subject on this list and this particular
> tutorial;
>
>
>
> http://wicketinaction.com/2009/06/wicketspringhibernate-configuration/
>
>
>
> And I'm still wondering, is this something that is actually possible? I
> could full understand that it wouldn't be - i.e. that the injector only
> works for Spring injection dependency and not AOP or anything else. So
> you inject your dependencies - and they have transaction support etc.
> But that means I'll be having to force fetching of lazily fetched
> children from outside the views themselves, which is obviously very
> painful. It would be so much easier to have transaction support in the
> view itself and not have to delegate.
>
>
>
> Any help would be greatly appreciated.
>
>
>
> The error message I'm receiving is;
>
>
>
> Caused by: org.hibernate.HibernateException: createCriteria is not valid
> without active transaction
>
>      at
> org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWra
> pper.invoke(ThreadLocalSessionContext.java:338)
>
>      at $Proxy15.createCriteria(Unknown Source)
>
>      at com.tenthart.tacs.testpres.HomePage.init(HomePage.java:39)
>
>      at com.tenthart.tacs.testpres.HomePage.(HomePage.java:28)
>
>      ... 34 more
>
>
>
> Cheers,
>
> Col
>
>
>
>
>
>
>
>
>
> Emap delivers intelligence, inspiration and access through publications, 
> events and data businesses in retail, media, the public sector and the built 
> environment. www.emap.com.
>
> The information in or attached to this email is confidential and may be 
> legally privileged. If you are not the intended recipient of this message any 
> use, disclosure, copying, distribution or any action taken in reliance on it 
> is prohibited and may be unlawful. If you have received this message in 
> error, please notify the sender immediately by return email or by telephone 
> on +44(0)207 728 5000 and delete this message and any copies from your 
> computer and network. The Emap group does not warrant that this email and any 
> attachments are free from viruses and accepts no liability for any loss 
> resulting from infected email transmissions.
>
> The Emap group reserves the right to monitor all e-mail communications 
> through its networks. Please note that any views expressed in this email may 
> be those of the originator and do not necessarily reflect those of the Emap 
> group.
>
> GroundSure Ltd. Company number 03421028 (England and Wales)
> Emap Limited. Company number: 0537204 (England and Wales).
&g

Re: [newbie] Wicket, Spring, Hibernate and transactions in views.

2010-03-02 Thread James Carman
Introduce AspectJ and spring-aspects into your build.  You can see an
example of it in my wicket-advanced sample project:

http://svn.carmanconsulting.com/public/wicket-advanced/trunk/

Then, AspectJ will weave the transaction support into your
Page/Component classes like you want.  There are limits on what type
of methods can be transactional, though.  I would also recommend the
OpenSessionInView filter (which my example project also uses).

On Tue, Mar 2, 2010 at 11:25 AM, Colin Rogers  wrote:
> All,
>
>
>
> I've got a bit of a newbie Wicket question involving Spring, Hibernate
> and transactions.
>
>
>
> The question that I can't seem to find an answer to;
>
>
>
> Can a view be a created/injected/aop'd like a spring bean so that it
> honours @Transactional methods for hibernate?
>
>
>
> An example;
>
>
>
> public class HomePage extends WebPage {
>
>
>
> @SpringBean // this is working fine
>
> private SessionFactory sessionFactory;
>
>
>
> public HomePage(final PageParameters parameters) {
>
>
>
> this.init();
>
>      }
>
>
>
>     �...@transactional // this is not working
>
>      public void init() {
>
>
>
>            Criteria criteria =
> sessionFactory.getCurrentSession().createCriteria(MyEntity.class);
>
>            List myEntities = criteria.list();
>
>            for( MyEntity myEntity : myEntities ) {
>
>
>
>                  // where subEntities is a lazy collection
>
>                  for( SubEntity subEntity : myEntity.getSubEntities() )
> {
>
>
>
>                        // ...
>
>                  }
>
>            }
>
> }
>
> }
>
>
>
> I've been reading Wicket In Action book, various places on the net and
> of course, emails on the subject on this list and this particular
> tutorial;
>
>
>
> http://wicketinaction.com/2009/06/wicketspringhibernate-configuration/
>
>
>
> And I'm still wondering, is this something that is actually possible? I
> could full understand that it wouldn't be - i.e. that the injector only
> works for Spring injection dependency and not AOP or anything else. So
> you inject your dependencies - and they have transaction support etc.
> But that means I'll be having to force fetching of lazily fetched
> children from outside the views themselves, which is obviously very
> painful. It would be so much easier to have transaction support in the
> view itself and not have to delegate.
>
>
>
> Any help would be greatly appreciated.
>
>
>
> The error message I'm receiving is;
>
>
>
> Caused by: org.hibernate.HibernateException: createCriteria is not valid
> without active transaction
>
>      at
> org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWra
> pper.invoke(ThreadLocalSessionContext.java:338)
>
>      at $Proxy15.createCriteria(Unknown Source)
>
>      at com.tenthart.tacs.testpres.HomePage.init(HomePage.java:39)
>
>      at com.tenthart.tacs.testpres.HomePage.(HomePage.java:28)
>
>      ... 34 more
>
>
>
> Cheers,
>
> Col
>
>
>
>
>
>
>
>
>
> Emap delivers intelligence, inspiration and access through publications, 
> events and data businesses in retail, media, the public sector and the built 
> environment. www.emap.com.
>
> The information in or attached to this email is confidential and may be 
> legally privileged. If you are not the intended recipient of this message any 
> use, disclosure, copying, distribution or any action taken in reliance on it 
> is prohibited and may be unlawful. If you have received this message in 
> error, please notify the sender immediately by return email or by telephone 
> on +44(0)207 728 5000 and delete this message and any copies from your 
> computer and network. The Emap group does not warrant that this email and any 
> attachments are free from viruses and accepts no liability for any loss 
> resulting from infected email transmissions.
>
> The Emap group reserves the right to monitor all e-mail communications 
> through its networks. Please note that any views expressed in this email may 
> be those of the originator and do not necessarily reflect those of the Emap 
> group.
>
> GroundSure Ltd. Company number 03421028 (England and Wales)
> Emap Limited. Company number: 0537204 (England and Wales).
> Registered Office: Greater London House, Hampstead Road, London NW1 7EJ, 
> United Kingdom.
> Details of the operating companies forming part of the Emap group can be 
> found at www.emap.com

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



RE: [newbie] Wicket, Spring, Hibernate and transactions in views.

2010-03-02 Thread Colin Rogers
.. 34 more
2010-03-02 17:19:12,751 DEBUG  207:OpenSessionInViewFilter - Closing
single Hibernate Session in OpenSessionInViewFilter
2010-03-02 17:19:12,751 DEBUG  207:OpenSessionInViewFilter - Closing
single Hibernate Session in OpenSessionInViewFilter
2010-03-02 17:19:12,798 DEBUG  239:OpenSessionInViewFilter - Using
SessionFactory 'sessionFactory' for OpenSessionInViewFilter
2010-03-02 17:19:12,798 DEBUG  239:OpenSessionInViewFilter - Using
SessionFactory 'sessionFactory' for OpenSessionInViewFilter
2010-03-02 17:19:12,798 DEBUG  181:OpenSessionInViewFilter - Opening
single Hibernate Session in OpenSessionInViewFilter
2010-03-02 17:19:12,798 DEBUG  181:OpenSessionInViewFilter - Opening
single Hibernate Session in OpenSessionInViewFilter
2010-03-02 17:19:12,798 DEBUG  207:OpenSessionInViewFilter - Closing
single Hibernate Session in OpenSessionInViewFilter
2010-03-02 17:19:12,798 DEBUG  207:OpenSessionInViewFilter - Closing
single Hibernate Session in OpenSessionInViewFilter

-Original Message-
From: Pedro Santos [mailto:pedros...@gmail.com] 
Sent: 02 March 2010 17:11
To: users@wicket.apache.org
Subject: Re: [newbie] Wicket, Spring, Hibernate and transactions in
views.

Consider to use OpenSessionInViewFilter

http://static.springsource.org/spring/docs/1.2.9/api/org/springframework
/orm/hibernate3/support/OpenSessionInViewFilter.html

The doc: "Intended for the "Open Session in View" pattern, i.e. to allow
for
lazy loading in web views despite the original transactions already
being
completed."

On Tue, Mar 2, 2010 at 2:05 PM, Colin Rogers 
wrote:

> " I'm not DB expert, but why are you using transactions for "read
only"
> (SELECTs) queries?"
>
> "If you aren't concerned with "good design" then I wouldn't worry
about
> transactions at all"
>
> Because you need the transactions for lazy fetching of child elements
in
> hibernate.
>
> -Original Message-
> From: Riyad Kalla [mailto:rka...@gmail.com]
> Sent: 02 March 2010 16:53
> To: users@wicket.apache.org
> Subject: Re: [newbie] Wicket, Spring, Hibernate and transactions in
> views.
>
> I'm not DB expert, but why are you using transactions for "read only"
> (SELECTs) queries? I've only ever seen transactions used to wrap
> INSERT/UPDATE/DELETE statements (writes)
>
> -R
>
> On Tue, Mar 2, 2010 at 9:46 AM, Colin Rogers 
> wrote:
>
> > "I'd recommend you to make your transactional control in your
services
> > and call them from your pages instead of trying to control it in
your
> > view."
> >
> > I'd agree in terms of "good design", but I'm coding something for
> myself
> > - and I'm trying to make it easy and as little time consuming as
> > possible. So, yes, transactions in the presentation layer is "bad" -
> but
> > it's only read-only transactions, so I'm letting myself off! ;)
> >
> > Having the transactionally controlled service methods, individually
> > instantiate all child entities by hand is also time consuming and
> would
> > potentially harm performance (if the view didn't need the children,
> for
> > example).
> >
> > -Original Message-
> > From: Pedro Sena [mailto:sena.pe...@gmail.com]
> > Sent: 02 March 2010 16:39
> > To: users@wicket.apache.org
> > Subject: Re: [newbie] Wicket, Spring, Hibernate and transactions in
> > views.
> >
> > I don't think so.
> >
> > I'd recommend you to make your transactional control in your
services
> > and
> > call them from your pages instead of trying to control it in your
> view.
> >
> > Best Regards,
> >
> > On Tue, Mar 2, 2010 at 1:25 PM, Colin Rogers

> > wrote:
> >
> > > All,
> > >
> > >
> > >
> > > I've got a bit of a newbie Wicket question involving Spring,
> Hibernate
> > > and transactions.
> > >
> > >
> > >
> > > The question that I can't seem to find an answer to;
> > >
> > >
> > >
> > > Can a view be a created/injected/aop'd like a spring bean so that
it
> > > honours @Transactional methods for hibernate?
> > >
> > >
> > >
> > > An example;
> > >
> > >
> > >
> > > public class HomePage extends WebPage {
> > >
> > >
> > >
> > > @SpringBean // this is working fine
> > >
> > > private SessionFactory sessionFactory;
> > >
> > >
> > >
> > > public HomePage(final PageParameters parameters) {
> > >

Re: [newbie] Wicket, Spring, Hibernate and transactions in views.

2010-03-02 Thread Pedro Santos
Consider to use OpenSessionInViewFilter

http://static.springsource.org/spring/docs/1.2.9/api/org/springframework/orm/hibernate3/support/OpenSessionInViewFilter.html

The doc: "Intended for the "Open Session in View" pattern, i.e. to allow for
lazy loading in web views despite the original transactions already being
completed."

On Tue, Mar 2, 2010 at 2:05 PM, Colin Rogers  wrote:

> " I'm not DB expert, but why are you using transactions for "read only"
> (SELECTs) queries?"
>
> "If you aren't concerned with "good design" then I wouldn't worry about
> transactions at all"
>
> Because you need the transactions for lazy fetching of child elements in
> hibernate.
>
> -Original Message-
> From: Riyad Kalla [mailto:rka...@gmail.com]
> Sent: 02 March 2010 16:53
> To: users@wicket.apache.org
> Subject: Re: [newbie] Wicket, Spring, Hibernate and transactions in
> views.
>
> I'm not DB expert, but why are you using transactions for "read only"
> (SELECTs) queries? I've only ever seen transactions used to wrap
> INSERT/UPDATE/DELETE statements (writes)
>
> -R
>
> On Tue, Mar 2, 2010 at 9:46 AM, Colin Rogers 
> wrote:
>
> > "I'd recommend you to make your transactional control in your services
> > and call them from your pages instead of trying to control it in your
> > view."
> >
> > I'd agree in terms of "good design", but I'm coding something for
> myself
> > - and I'm trying to make it easy and as little time consuming as
> > possible. So, yes, transactions in the presentation layer is "bad" -
> but
> > it's only read-only transactions, so I'm letting myself off! ;)
> >
> > Having the transactionally controlled service methods, individually
> > instantiate all child entities by hand is also time consuming and
> would
> > potentially harm performance (if the view didn't need the children,
> for
> > example).
> >
> > -Original Message-
> > From: Pedro Sena [mailto:sena.pe...@gmail.com]
> > Sent: 02 March 2010 16:39
> > To: users@wicket.apache.org
> > Subject: Re: [newbie] Wicket, Spring, Hibernate and transactions in
> > views.
> >
> > I don't think so.
> >
> > I'd recommend you to make your transactional control in your services
> > and
> > call them from your pages instead of trying to control it in your
> view.
> >
> > Best Regards,
> >
> > On Tue, Mar 2, 2010 at 1:25 PM, Colin Rogers 
> > wrote:
> >
> > > All,
> > >
> > >
> > >
> > > I've got a bit of a newbie Wicket question involving Spring,
> Hibernate
> > > and transactions.
> > >
> > >
> > >
> > > The question that I can't seem to find an answer to;
> > >
> > >
> > >
> > > Can a view be a created/injected/aop'd like a spring bean so that it
> > > honours @Transactional methods for hibernate?
> > >
> > >
> > >
> > > An example;
> > >
> > >
> > >
> > > public class HomePage extends WebPage {
> > >
> > >
> > >
> > > @SpringBean // this is working fine
> > >
> > > private SessionFactory sessionFactory;
> > >
> > >
> > >
> > > public HomePage(final PageParameters parameters) {
> > >
> > >
> > >
> > > this.init();
> > >
> > >  }
> > >
> > >
> > >
> > >  @Transactional // this is not working
> > >
> > >  public void init() {
> > >
> > >
> > >
> > >Criteria criteria =
> > > sessionFactory.getCurrentSession().createCriteria(MyEntity.class);
> > >
> > >List myEntities = criteria.list();
> > >
> > >for( MyEntity myEntity : myEntities ) {
> > >
> > >
> > >
> > >  // where subEntities is a lazy collection
> > >
> > >  for( SubEntity subEntity :
> myEntity.getSubEntities()
> > )
> > > {
> > >
> > >
> > >
> > >// ...
> > >
> > >  }
> > >
> > >}
> > >
> > > }
> > >
> > > }
> > >
> > >
> > >
> > > I've been reading Wicket In Action book, various places on the net
>

RE: [newbie] Wicket, Spring, Hibernate and transactions in views.

2010-03-02 Thread Colin Rogers
" I'm not DB expert, but why are you using transactions for "read only"
(SELECTs) queries?"

"If you aren't concerned with "good design" then I wouldn't worry about
transactions at all"

Because you need the transactions for lazy fetching of child elements in
hibernate.

-Original Message-
From: Riyad Kalla [mailto:rka...@gmail.com] 
Sent: 02 March 2010 16:53
To: users@wicket.apache.org
Subject: Re: [newbie] Wicket, Spring, Hibernate and transactions in
views.

I'm not DB expert, but why are you using transactions for "read only"
(SELECTs) queries? I've only ever seen transactions used to wrap
INSERT/UPDATE/DELETE statements (writes)

-R

On Tue, Mar 2, 2010 at 9:46 AM, Colin Rogers 
wrote:

> "I'd recommend you to make your transactional control in your services
> and call them from your pages instead of trying to control it in your
> view."
>
> I'd agree in terms of "good design", but I'm coding something for
myself
> - and I'm trying to make it easy and as little time consuming as
> possible. So, yes, transactions in the presentation layer is "bad" -
but
> it's only read-only transactions, so I'm letting myself off! ;)
>
> Having the transactionally controlled service methods, individually
> instantiate all child entities by hand is also time consuming and
would
> potentially harm performance (if the view didn't need the children,
for
> example).
>
> -----Original Message-
> From: Pedro Sena [mailto:sena.pe...@gmail.com]
> Sent: 02 March 2010 16:39
> To: users@wicket.apache.org
> Subject: Re: [newbie] Wicket, Spring, Hibernate and transactions in
> views.
>
> I don't think so.
>
> I'd recommend you to make your transactional control in your services
> and
> call them from your pages instead of trying to control it in your
view.
>
> Best Regards,
>
> On Tue, Mar 2, 2010 at 1:25 PM, Colin Rogers 
> wrote:
>
> > All,
> >
> >
> >
> > I've got a bit of a newbie Wicket question involving Spring,
Hibernate
> > and transactions.
> >
> >
> >
> > The question that I can't seem to find an answer to;
> >
> >
> >
> > Can a view be a created/injected/aop'd like a spring bean so that it
> > honours @Transactional methods for hibernate?
> >
> >
> >
> > An example;
> >
> >
> >
> > public class HomePage extends WebPage {
> >
> >
> >
> > @SpringBean // this is working fine
> >
> > private SessionFactory sessionFactory;
> >
> >
> >
> > public HomePage(final PageParameters parameters) {
> >
> >
> >
> > this.init();
> >
> >  }
> >
> >
> >
> >  @Transactional // this is not working
> >
> >  public void init() {
> >
> >
> >
> >Criteria criteria =
> > sessionFactory.getCurrentSession().createCriteria(MyEntity.class);
> >
> >List myEntities = criteria.list();
> >
> >for( MyEntity myEntity : myEntities ) {
> >
> >
> >
> >  // where subEntities is a lazy collection
> >
> >  for( SubEntity subEntity :
myEntity.getSubEntities()
> )
> > {
> >
> >
> >
> >// ...
> >
> >  }
> >
> >}
> >
> > }
> >
> > }
> >
> >
> >
> > I've been reading Wicket In Action book, various places on the net
and
> > of course, emails on the subject on this list and this particular
> > tutorial;
> >
> >
> >
> >
http://wicketinaction.com/2009/06/wicketspringhibernate-configuration/
> >
> >
> >
> > And I'm still wondering, is this something that is actually
possible?
> I
> > could full understand that it wouldn't be - i.e. that the injector
> only
> > works for Spring injection dependency and not AOP or anything else.
So
> > you inject your dependencies - and they have transaction support
etc.
> > But that means I'll be having to force fetching of lazily fetched
> > children from outside the views themselves, which is obviously very
> > painful. It would be so much easier to have transaction support in
the
> > view itself and not have to delegate.
> >
> >
> >
> > Any help would be greatly appreciated.
> >
> >
> >
> > The error message I'm receiving is;
> >
> >
> >
> > Caused by: org.hibernate.HibernateEx

Re: [newbie] Wicket, Spring, Hibernate and transactions in views.

2010-03-02 Thread Riyad Kalla
I'm not DB expert, but why are you using transactions for "read only"
(SELECTs) queries? I've only ever seen transactions used to wrap
INSERT/UPDATE/DELETE statements (writes)

-R

On Tue, Mar 2, 2010 at 9:46 AM, Colin Rogers  wrote:

> "I'd recommend you to make your transactional control in your services
> and call them from your pages instead of trying to control it in your
> view."
>
> I'd agree in terms of "good design", but I'm coding something for myself
> - and I'm trying to make it easy and as little time consuming as
> possible. So, yes, transactions in the presentation layer is "bad" - but
> it's only read-only transactions, so I'm letting myself off! ;)
>
> Having the transactionally controlled service methods, individually
> instantiate all child entities by hand is also time consuming and would
> potentially harm performance (if the view didn't need the children, for
> example).
>
> -Original Message-
> From: Pedro Sena [mailto:sena.pe...@gmail.com]
> Sent: 02 March 2010 16:39
> To: users@wicket.apache.org
> Subject: Re: [newbie] Wicket, Spring, Hibernate and transactions in
> views.
>
> I don't think so.
>
> I'd recommend you to make your transactional control in your services
> and
> call them from your pages instead of trying to control it in your view.
>
> Best Regards,
>
> On Tue, Mar 2, 2010 at 1:25 PM, Colin Rogers 
> wrote:
>
> > All,
> >
> >
> >
> > I've got a bit of a newbie Wicket question involving Spring, Hibernate
> > and transactions.
> >
> >
> >
> > The question that I can't seem to find an answer to;
> >
> >
> >
> > Can a view be a created/injected/aop'd like a spring bean so that it
> > honours @Transactional methods for hibernate?
> >
> >
> >
> > An example;
> >
> >
> >
> > public class HomePage extends WebPage {
> >
> >
> >
> > @SpringBean // this is working fine
> >
> > private SessionFactory sessionFactory;
> >
> >
> >
> > public HomePage(final PageParameters parameters) {
> >
> >
> >
> > this.init();
> >
> >  }
> >
> >
> >
> >  @Transactional // this is not working
> >
> >  public void init() {
> >
> >
> >
> >Criteria criteria =
> > sessionFactory.getCurrentSession().createCriteria(MyEntity.class);
> >
> >List myEntities = criteria.list();
> >
> >for( MyEntity myEntity : myEntities ) {
> >
> >
> >
> >  // where subEntities is a lazy collection
> >
> >  for( SubEntity subEntity : myEntity.getSubEntities()
> )
> > {
> >
> >
> >
> >// ...
> >
> >  }
> >
> >}
> >
> > }
> >
> > }
> >
> >
> >
> > I've been reading Wicket In Action book, various places on the net and
> > of course, emails on the subject on this list and this particular
> > tutorial;
> >
> >
> >
> > http://wicketinaction.com/2009/06/wicketspringhibernate-configuration/
> >
> >
> >
> > And I'm still wondering, is this something that is actually possible?
> I
> > could full understand that it wouldn't be - i.e. that the injector
> only
> > works for Spring injection dependency and not AOP or anything else. So
> > you inject your dependencies - and they have transaction support etc.
> > But that means I'll be having to force fetching of lazily fetched
> > children from outside the views themselves, which is obviously very
> > painful. It would be so much easier to have transaction support in the
> > view itself and not have to delegate.
> >
> >
> >
> > Any help would be greatly appreciated.
> >
> >
> >
> > The error message I'm receiving is;
> >
> >
> >
> > Caused by: org.hibernate.HibernateException: createCriteria is not
> valid
> > without active transaction
> >
> >  at
> >
> org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWra
> > pper.invoke(ThreadLocalSessionContext.java:338)
> >
> >  at $Proxy15.createCriteria(Unknown Source)
> >
> >  at com.tenthart.tacs.testpres.HomePage.init(HomePage.java:39)
> >
> >  at com.tenthart.tacs.testpres.HomePage.(HomePage.java:28)
> >
> >  ... 34 mor

RE: [newbie] Wicket, Spring, Hibernate and transactions in views.

2010-03-02 Thread Josh Chappelle
If you aren't concerned with "good design" then I wouldn't worry about
transactions at all. Especially if you are doing read only data retrieval. 

Once you get the code working the way you want you can always add
transactions later and refactor the code into your service methods. That's
the agile method anyway. :-)

Josh

-Original Message-
From: Colin Rogers [mailto:coli...@groundsure.com] 
Sent: Tuesday, March 02, 2010 10:46 AM
To: users@wicket.apache.org
Subject: RE: [newbie] Wicket, Spring, Hibernate and transactions in views.

"I'd recommend you to make your transactional control in your services
and call them from your pages instead of trying to control it in your
view."

I'd agree in terms of "good design", but I'm coding something for myself
- and I'm trying to make it easy and as little time consuming as
possible. So, yes, transactions in the presentation layer is "bad" - but
it's only read-only transactions, so I'm letting myself off! ;)

Having the transactionally controlled service methods, individually
instantiate all child entities by hand is also time consuming and would
potentially harm performance (if the view didn't need the children, for
example).

-Original Message-
From: Pedro Sena [mailto:sena.pe...@gmail.com] 
Sent: 02 March 2010 16:39
To: users@wicket.apache.org
Subject: Re: [newbie] Wicket, Spring, Hibernate and transactions in
views.

I don't think so.

I'd recommend you to make your transactional control in your services
and
call them from your pages instead of trying to control it in your view.

Best Regards,

On Tue, Mar 2, 2010 at 1:25 PM, Colin Rogers 
wrote:

> All,
>
>
>
> I've got a bit of a newbie Wicket question involving Spring, Hibernate
> and transactions.
>
>
>
> The question that I can't seem to find an answer to;
>
>
>
> Can a view be a created/injected/aop'd like a spring bean so that it
> honours @Transactional methods for hibernate?
>
>
>
> An example;
>
>
>
> public class HomePage extends WebPage {
>
>
>
> @SpringBean // this is working fine
>
> private SessionFactory sessionFactory;
>
>
>
> public HomePage(final PageParameters parameters) {
>
>
>
> this.init();
>
>  }
>
>
>
>  @Transactional // this is not working
>
>  public void init() {
>
>
>
>Criteria criteria =
> sessionFactory.getCurrentSession().createCriteria(MyEntity.class);
>
>List myEntities = criteria.list();
>
>for( MyEntity myEntity : myEntities ) {
>
>
>
>  // where subEntities is a lazy collection
>
>  for( SubEntity subEntity : myEntity.getSubEntities()
)
> {
>
>
>
>// ...
>
>  }
>
>}
>
> }
>
> }
>
>
>
> I've been reading Wicket In Action book, various places on the net and
> of course, emails on the subject on this list and this particular
> tutorial;
>
>
>
> http://wicketinaction.com/2009/06/wicketspringhibernate-configuration/
>
>
>
> And I'm still wondering, is this something that is actually possible?
I
> could full understand that it wouldn't be - i.e. that the injector
only
> works for Spring injection dependency and not AOP or anything else. So
> you inject your dependencies - and they have transaction support etc.
> But that means I'll be having to force fetching of lazily fetched
> children from outside the views themselves, which is obviously very
> painful. It would be so much easier to have transaction support in the
> view itself and not have to delegate.
>
>
>
> Any help would be greatly appreciated.
>
>
>
> The error message I'm receiving is;
>
>
>
> Caused by: org.hibernate.HibernateException: createCriteria is not
valid
> without active transaction
>
>  at
>
org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWra
> pper.invoke(ThreadLocalSessionContext.java:338)
>
>  at $Proxy15.createCriteria(Unknown Source)
>
>  at com.tenthart.tacs.testpres.HomePage.init(HomePage.java:39)
>
>  at com.tenthart.tacs.testpres.HomePage.(HomePage.java:28)
>
>  ... 34 more
>
>
>
> Cheers,
>
> Col
>
>
>
>
>
>
>
>
>
> Emap delivers intelligence, inspiration and access through
publications,
> events and data businesses in retail, media, the public sector and the
built
> environment. www.emap.com.
>
> The information in or attached to this email is confidential and may
be
> legally privileged. If you are not the intended recipient of this
message
> any

RE: [newbie] Wicket, Spring, Hibernate and transactions in views.

2010-03-02 Thread Colin Rogers
"I'd recommend you to make your transactional control in your services
and call them from your pages instead of trying to control it in your
view."

I'd agree in terms of "good design", but I'm coding something for myself
- and I'm trying to make it easy and as little time consuming as
possible. So, yes, transactions in the presentation layer is "bad" - but
it's only read-only transactions, so I'm letting myself off! ;)

Having the transactionally controlled service methods, individually
instantiate all child entities by hand is also time consuming and would
potentially harm performance (if the view didn't need the children, for
example).

-Original Message-
From: Pedro Sena [mailto:sena.pe...@gmail.com] 
Sent: 02 March 2010 16:39
To: users@wicket.apache.org
Subject: Re: [newbie] Wicket, Spring, Hibernate and transactions in
views.

I don't think so.

I'd recommend you to make your transactional control in your services
and
call them from your pages instead of trying to control it in your view.

Best Regards,

On Tue, Mar 2, 2010 at 1:25 PM, Colin Rogers 
wrote:

> All,
>
>
>
> I've got a bit of a newbie Wicket question involving Spring, Hibernate
> and transactions.
>
>
>
> The question that I can't seem to find an answer to;
>
>
>
> Can a view be a created/injected/aop'd like a spring bean so that it
> honours @Transactional methods for hibernate?
>
>
>
> An example;
>
>
>
> public class HomePage extends WebPage {
>
>
>
> @SpringBean // this is working fine
>
> private SessionFactory sessionFactory;
>
>
>
> public HomePage(final PageParameters parameters) {
>
>
>
> this.init();
>
>  }
>
>
>
>  @Transactional // this is not working
>
>  public void init() {
>
>
>
>Criteria criteria =
> sessionFactory.getCurrentSession().createCriteria(MyEntity.class);
>
>List myEntities = criteria.list();
>
>for( MyEntity myEntity : myEntities ) {
>
>
>
>  // where subEntities is a lazy collection
>
>  for( SubEntity subEntity : myEntity.getSubEntities()
)
> {
>
>
>
>// ...
>
>  }
>
>}
>
> }
>
> }
>
>
>
> I've been reading Wicket In Action book, various places on the net and
> of course, emails on the subject on this list and this particular
> tutorial;
>
>
>
> http://wicketinaction.com/2009/06/wicketspringhibernate-configuration/
>
>
>
> And I'm still wondering, is this something that is actually possible?
I
> could full understand that it wouldn't be - i.e. that the injector
only
> works for Spring injection dependency and not AOP or anything else. So
> you inject your dependencies - and they have transaction support etc.
> But that means I'll be having to force fetching of lazily fetched
> children from outside the views themselves, which is obviously very
> painful. It would be so much easier to have transaction support in the
> view itself and not have to delegate.
>
>
>
> Any help would be greatly appreciated.
>
>
>
> The error message I'm receiving is;
>
>
>
> Caused by: org.hibernate.HibernateException: createCriteria is not
valid
> without active transaction
>
>  at
>
org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWra
> pper.invoke(ThreadLocalSessionContext.java:338)
>
>  at $Proxy15.createCriteria(Unknown Source)
>
>  at com.tenthart.tacs.testpres.HomePage.init(HomePage.java:39)
>
>  at com.tenthart.tacs.testpres.HomePage.(HomePage.java:28)
>
>  ... 34 more
>
>
>
> Cheers,
>
> Col
>
>
>
>
>
>
>
>
>
> Emap delivers intelligence, inspiration and access through
publications,
> events and data businesses in retail, media, the public sector and the
built
> environment. www.emap.com.
>
> The information in or attached to this email is confidential and may
be
> legally privileged. If you are not the intended recipient of this
message
> any use, disclosure, copying, distribution or any action taken in
reliance
> on it is prohibited and may be unlawful. If you have received this
message
> in error, please notify the sender immediately by return email or by
> telephone on +44(0)207 728 5000 and delete this message and any copies
from
> your computer and network. The Emap group does not warrant that this
email
> and any attachments are free from viruses and accepts no liability for
any
> loss resulting from infected email transmissions.
>
> The Emap group reserves the right to monitor all e-m

Re: [newbie] Wicket, Spring, Hibernate and transactions in views.

2010-03-02 Thread Pedro Sena
I don't think so.

I'd recommend you to make your transactional control in your services and
call them from your pages instead of trying to control it in your view.

Best Regards,

On Tue, Mar 2, 2010 at 1:25 PM, Colin Rogers  wrote:

> All,
>
>
>
> I've got a bit of a newbie Wicket question involving Spring, Hibernate
> and transactions.
>
>
>
> The question that I can't seem to find an answer to;
>
>
>
> Can a view be a created/injected/aop'd like a spring bean so that it
> honours @Transactional methods for hibernate?
>
>
>
> An example;
>
>
>
> public class HomePage extends WebPage {
>
>
>
> @SpringBean // this is working fine
>
> private SessionFactory sessionFactory;
>
>
>
> public HomePage(final PageParameters parameters) {
>
>
>
> this.init();
>
>  }
>
>
>
>  @Transactional // this is not working
>
>  public void init() {
>
>
>
>Criteria criteria =
> sessionFactory.getCurrentSession().createCriteria(MyEntity.class);
>
>List myEntities = criteria.list();
>
>for( MyEntity myEntity : myEntities ) {
>
>
>
>  // where subEntities is a lazy collection
>
>  for( SubEntity subEntity : myEntity.getSubEntities() )
> {
>
>
>
>// ...
>
>  }
>
>}
>
> }
>
> }
>
>
>
> I've been reading Wicket In Action book, various places on the net and
> of course, emails on the subject on this list and this particular
> tutorial;
>
>
>
> http://wicketinaction.com/2009/06/wicketspringhibernate-configuration/
>
>
>
> And I'm still wondering, is this something that is actually possible? I
> could full understand that it wouldn't be - i.e. that the injector only
> works for Spring injection dependency and not AOP or anything else. So
> you inject your dependencies - and they have transaction support etc.
> But that means I'll be having to force fetching of lazily fetched
> children from outside the views themselves, which is obviously very
> painful. It would be so much easier to have transaction support in the
> view itself and not have to delegate.
>
>
>
> Any help would be greatly appreciated.
>
>
>
> The error message I'm receiving is;
>
>
>
> Caused by: org.hibernate.HibernateException: createCriteria is not valid
> without active transaction
>
>  at
> org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWra
> pper.invoke(ThreadLocalSessionContext.java:338)
>
>  at $Proxy15.createCriteria(Unknown Source)
>
>  at com.tenthart.tacs.testpres.HomePage.init(HomePage.java:39)
>
>  at com.tenthart.tacs.testpres.HomePage.(HomePage.java:28)
>
>  ... 34 more
>
>
>
> Cheers,
>
> Col
>
>
>
>
>
>
>
>
>
> Emap delivers intelligence, inspiration and access through publications,
> events and data businesses in retail, media, the public sector and the built
> environment. www.emap.com.
>
> The information in or attached to this email is confidential and may be
> legally privileged. If you are not the intended recipient of this message
> any use, disclosure, copying, distribution or any action taken in reliance
> on it is prohibited and may be unlawful. If you have received this message
> in error, please notify the sender immediately by return email or by
> telephone on +44(0)207 728 5000 and delete this message and any copies from
> your computer and network. The Emap group does not warrant that this email
> and any attachments are free from viruses and accepts no liability for any
> loss resulting from infected email transmissions.
>
> The Emap group reserves the right to monitor all e-mail communications
> through its networks. Please note that any views expressed in this email may
> be those of the originator and do not necessarily reflect those of the Emap
> group.
>
> GroundSure Ltd. Company number 03421028 (England and Wales)
> Emap Limited. Company number: 0537204 (England and Wales).
> Registered Office: Greater London House, Hampstead Road, London NW1 7EJ,
> United Kingdom.
> Details of the operating companies forming part of the Emap group can be
> found at www.emap.com




-- 
/**
* Pedro Sena
* Systems Architect
* Sun Certified Java Programmer
* Sun Certified Web Component Developer
*/