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 <coli...@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-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org