You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Colin Rogers <co...@groundsure.com> on 2010/03/02 17:25:46 UTC
[newbie] Wicket, Spring, Hibernate and transactions in views.
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<MyEntity> 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.<init>(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
RE: [newbie] Wicket, Spring, Hibernate and transactions in views.
Posted by Colin Rogers <co...@groundsure.com>.
Thats exactly what I am using, but it doesn't seem to work.
I've set up as per the original posts tutorial (that includes
OpenSessionInViewFilter).
The log below show me calling it - and supposedly opening the
transaction (although it does do everything twice);
2010-03-02 17:19:08.690::INFO: Started
SelectChannelConnector@0.0.0.0:8080
2010-03-02 17:19:12,439 DEBUG 239:OpenSessionInViewFilter - Using
SessionFactory 'sessionFactory' for OpenSessionInViewFilter
2010-03-02 17:19:12,439 DEBUG 239:OpenSessionInViewFilter - Using
SessionFactory 'sessionFactory' for OpenSessionInViewFilter
2010-03-02 17:19:12,439 DEBUG 181:OpenSessionInViewFilter - Opening
single Hibernate Session in OpenSessionInViewFilter
2010-03-02 17:19:12,439 DEBUG 181:OpenSessionInViewFilter - Opening
single Hibernate Session in OpenSessionInViewFilter
2010-03-02 17:19:12,595 ERROR 1521:RequestCycle - Can't
instantiate page using constructor public
com.tenthart.tacs.testpres.HomePage(org.apache.wicket.PageParameters)
and argument
org.apache.wicket.WicketRuntimeException: Can't instantiate page using
constructor public
com.tenthart.tacs.testpres.HomePage(org.apache.wicket.PageParameters)
and argument
at
org.apache.wicket.session.DefaultPageFactory.createPage(DefaultPageFacto
ry.java:212)
at
org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.
java:65)
at
org.apache.wicket.request.target.component.BookmarkablePageRequestTarget
.newPage(BookmarkablePageRequestTarget.java:298)
at
org.apache.wicket.request.target.component.BookmarkablePageRequestTarget
.getPage(BookmarkablePageRequestTarget.java:320)
at
org.apache.wicket.request.target.component.BookmarkablePageRequestTarget
.processEvents(BookmarkablePageRequestTarget.java:234)
at
org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(Ab
stractRequestCycleProcessor.java:92)
at
org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java
:1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at
org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479
)
at
org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:
312)
at
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHan
dler.java:1084)
at
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFil
terInternal(OpenSessionInViewFilter.java:198)
at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequ
estFilter.java:76)
at
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHan
dler.java:1084)
at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:2
16)
at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:722)
at
org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:404)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
at org.mortbay.jetty.Server.handle(Server.java:324)
at
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at
org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConne
ction.java:828)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)
at
org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at
org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:
395)
at
org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.ja
va:450)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorA
ccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingCons
tructorAccessorImpl.java:27)
at
java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at
org.apache.wicket.session.DefaultPageFactory.createPage(DefaultPageFacto
ry.java:188)
... 29 more
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:41)
at com.tenthart.tacs.testpres.HomePage.<init>(HomePage.java:28)
... 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:pedrosans@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 <co...@groundsure.com>
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:rkalla@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 <co...@groundsure.com>
> 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.pedro@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
<co...@groundsure.com>
> > 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<MyEntity> 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.<init>(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
> > */
> >
> >
> > 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-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
>
> 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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
--
Pedro Henrique Oliveira dos Santos
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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: [newbie] Wicket, Spring, Hibernate and transactions in views.
Posted by Pedro Santos <pe...@gmail.com>.
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 <co...@groundsure.com> 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:rkalla@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 <co...@groundsure.com>
> 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.pedro@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 <co...@groundsure.com>
> > 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<MyEntity> 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.<init>(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
> > */
> >
> >
> > 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-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
>
> 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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
--
Pedro Henrique Oliveira dos Santos
RE: [newbie] Wicket, Spring, Hibernate and transactions in views.
Posted by Colin Rogers <co...@groundsure.com>.
" 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:rkalla@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 <co...@groundsure.com>
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.pedro@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 <co...@groundsure.com>
> 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<MyEntity> 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.<init>(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
> */
>
>
> 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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: [newbie] Wicket, Spring, Hibernate and transactions in views.
Posted by Riyad Kalla <rk...@gmail.com>.
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 <co...@groundsure.com> 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.pedro@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 <co...@groundsure.com>
> 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<MyEntity> 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.<init>(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
> */
>
>
> 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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
RE: [newbie] Wicket, Spring, Hibernate and transactions in views.
Posted by Josh Chappelle <jc...@4redi.com>.
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:colin-r@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.pedro@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 <co...@groundsure.com>
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<MyEntity> 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.<init>(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
*/
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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
RE: [newbie] Wicket, Spring, Hibernate and transactions in views.
Posted by Colin Rogers <co...@groundsure.com>.
"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.pedro@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 <co...@groundsure.com>
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<MyEntity> 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.<init>(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
*/
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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: [newbie] Wicket, Spring, Hibernate and transactions in views.
Posted by Pedro Sena <se...@gmail.com>.
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 <co...@groundsure.com> 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<MyEntity> 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.<init>(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
*/
RE: [newbie] Wicket, Spring, Hibernate and transactions in views.
Posted by Colin Rogers <co...@groundsure.com>.
James,
Thank you very much for that - a working example is exactly what I need! :)
Cheers,
Col.
-----Original Message-----
From: James Carman [mailto:jcarman@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 <co...@groundsure.com> 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<MyEntity> 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.<init>(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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: [newbie] Wicket, Spring, Hibernate and transactions in views.
Posted by James Carman <jc...@carmanconsulting.com>.
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 <co...@groundsure.com> 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<MyEntity> 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.<init>(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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org