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

Reply via email to