You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Gonzalo Aguilar Delgado <ga...@aguilardelgado.com> on 2011/06/04 14:31:41 UTC

Re: setReuseItems(true) + transactions = ERROR (Solved!)

Oh man... It's almost solved but a lot of things happened in the middle:

        1.- I was using wicket examples configurations that makes no use
        of the org.apache.wicket.spring.SpringWebApplicationFactory in
        the WicketFilter. I normally use it but for this project wanted
        to stick to wicket example pages format. Solved problem 1 ->
        change filter definition.
        
        2.- wicket exampled had lots of libraries inside WEB-INF/lib. I
        didn't realized of this and everything got mixed. Different
        libraries, different versions all different. Solved problem 2 ->
        remove libraries and add dependencies to maven.
        
        3.- Filters!!! The order of the filters does matter. :D the OSIV
        MUST be mapped before the wicket filter. I thought that I knew
        this but did it wrooong. Solved problem 3 -> put OSIV before any
        other filter.
        
        
With this everything backs to work. The only problem that I have to
check now are transactions, and the order of doing things. Now object
got loaded after model updates and it lost changes before saving. But
the actual saving works. 


Thank you all guys!!! 

Hope this e-mail serves as reference to others... :D








El sáb, 04-06-2011 a las 07:27 -0400, James Carman escribió:
> Can you try to replicate what you're doing in a more simple fashion?
> Take your wicket framework code out of the mix.  Just try a
> wicket/spring/hibernate example.  You can use the Wicketopia example
> as a template if you want.
> 
> On Sat, Jun 4, 2011 at 6:01 AM, Gonzalo Aguilar Delgado
> <ga...@aguilardelgado.com> wrote:
> > I removed transactional pointcuts to see if this removes the issue.
> >
> > But the problem got worse. It seems that something is really wrong
> > configured in my project.
> >
> > DEBUG - DefaultListableBeanFactory - Returning cached instance of
> > singleton bean 'leadDAOBean'
> > DEBUG - SessionFactoryUtils        - Opening Hibernate Session
> > DEBUG - SessionImpl                - opened session at timestamp:
> > 13071814596
> > DEBUG - SessionFactoryUtils        - Closing Hibernate Session
> > ERROR - RequestCycle               - Can't instantiate page using
> > constructor public
> > org.apache.wicket.examples.wscaffold.basicform.BasicFormPage()
> > org.apache.wicket.WicketRuntimeException: Can't instantiate page using
> > constructor public
> > org.apache.wicket.examples.wscaffold.basicform.BasicFormPage()
> >
> > Watch this:
> >  SessionFactoryUtils        - Opening Hibernate Session
> >
> > It seems that is not the OSIV filter. It's hibernate who opens the
> > session. Why?
> >
> > It's strange because OSIV is configured:
> > DEBUG - OpenSessionInViewFilter    - Initializing filter
> > 'openSessionInViewFilter'
> > DEBUG - OpenSessionInViewFilter    - Filter 'openSessionInViewFilter'
> > configured successfully
> >
> > And the problem got worse without transactions:
> >
> > WicketMessage: Can't instantiate page using constructor public
> > org.apache.wicket.examples.wscaffold.basicform.BasicFormPage()
> >
> > Root cause:
> >
> > org.hibernate.HibernateException: No Hibernate Session bound to thread,
> > and configuration does not allow creation of non-transactional one here
> >
> > Not even the first page is instantiated...
> >
> > Will search more...
> >
> >
> >
> >
> >
> > El sáb, 04-06-2011 a las 11:28 +0200, Gonzalo Aguilar Delgado escribió:
> >> >Hi,
> >> >are you sure your model is a LDM?
> >>
> >> Yes. Sure. Encapsulated by an CompoundPropertyModel.
> >> -------
> >> new CompoundPropertyModel(scaffoldableModel)
> >> -------
> >> /*
> >>                * Need this because wicket serializes everything and need to reload
> >> it when
> >>                * it's needed. This way wicket and hibernate plays well
> >>                */
> >>               IModel<Lead> scaffoldableModel = new
> >> LoadableHibernateModelImpl<Lead>(getFirst())
> >>               {
> >>                       /**
> >>                        *
> >>                        */
> >>                       private static final long serialVersionUID = 1L;
> >>                       @SpringBean(name = "leadDAOBean")
> >>                       private LeadDAO leadDAO;
> >>                       private UuidUserType uuid;
> >>
> >>                       @Override
> >>                       protected Lead load() {
> >>                               Lead lead = null;
> >>                               if(uuid!=null)
> >>                               {
> >>                                       lead = leadDAO.find(uuid);
> >>
> >>                               }
> >>                               return lead;
> >>                       }
> >>
> >>                       @Override
> >>                       protected void setNonTransientObject() {
> >>                               Lead lead =  this.getObject();
> >>                               if(lead!=null)
> >>                                       uuid = lead.getUuid();
> >>                       }
> >>
> >>
> >>               };
> >>
> >> --------
> >> And...
> >> ---------
> >> public abstract class LoadableHibernateModelImpl<T> extends
> >> LoadableDetachableModel<T>
> >>       implements LoadableHibernateModel<T>, IModel<T>
> >> ---------
> >>
> >> detach and load got called. So it's working. The problem seems to be
> >> transactions.
> >>
> >> I used to reload the model in the onBeforeRender functions. This made
> >> wicked open a transaction that continued until the save. But now I made
> >> things different (more efficient). The problem now is how to get a
> >> transaction run during the model update and save.
> >>
> >>
> >>
> >> >>IIRC you have a ListView involved. What's the type of
> >> >>this.getDefaultModel() ?
> >>
> >> I checked this to make sure is the correct model. What I do is to set a
> >> wrapper around. The component I use extends from panel and inside there
> >> is a form and some other components that must use the model of the
> >> panel. So I wrap it around with CompoundPropertyModel.
> >>
> >> ---------------
> >>       public ScaffoldingForm(String id, IModel<T> scaffoldableModel) {
> >>               //super(id, scaffoldableModel);
> >>               super(id, new CompoundPropertyModel(scaffoldableModel));
> >> ---------------
> >>
> >> The returning model is the CompoundPropertyModel. So seems to be ok.
> >>
> >>
> >> Thank you in advance Sven.
> >> I will try to make everything run in a unique transaction. I found this:
> >> http://apache-wicket.1842946.n4.nabble.com/OpenSessionInView-OSIV-LoadableDetachableModel-and-Transactions-td1858513.html
> >>
> >> Maybe someone else have any other useful link.
> >>
> >> Thank you again.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> 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
> >
> >
> 
> ---------------------------------------------------------------------
> 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: setReuseItems(true) + transactions = ERROR (Solved!)

Posted by Gonzalo Aguilar Delgado <ga...@aguilardelgado.com>.
Without transactions it works now. With few implications.

	1.- I have to put singleSession to true. Otherwise it fails:
	<filter>
		<filter-name>openSessionInViewFilter</filter-name>

<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
		<init-param>
			<param-name>singleSession</param-name>
			<param-value>true</param-value>
		</init-param>
		<init-param>
			<param-name>sessionFactoryBeanName</param-name>
			<param-value>opCustomerSessionFactory</param-value>
		</init-param>
	</filter>


	2.- I have to flush manually the session after saving. Because if I
don't do it database got not updated. Any directions here? Seems to be
normal as there are no transaction delimiters. But should be normal to
flush database when session ends. 
	Unfortunately the object got reloaded from the database before it
happens because it must be shown again in the form. I think because of
this the object returns to the previous values. But I don't know if this
is normal. 

Anyway this works:
			@Override
			protected void onSubmit() {
				log.debug("Saving content");
				IModel model = this.getDefaultModel();
				Lead object = (Lead)model.getObject();
				if(leadDAO!=null && object!=null)
				{
						leadDAO.save(object);
						leadDAO.flush();

				}
				
			}
			
		};


Hope it helps someone.


El sáb, 04-06-2011 a las 14:31 +0200, Gonzalo Aguilar Delgado escribió:
> Oh man... It's almost solved but a lot of things happened in the middle:
> 
>         1.- I was using wicket examples configurations that makes no use
>         of the org.apache.wicket.spring.SpringWebApplicationFactory in
>         the WicketFilter. I normally use it but for this project wanted
>         to stick to wicket example pages format. Solved problem 1 ->
>         change filter definition.
>         
>         2.- wicket exampled had lots of libraries inside WEB-INF/lib. I
>         didn't realized of this and everything got mixed. Different
>         libraries, different versions all different. Solved problem 2 ->
>         remove libraries and add dependencies to maven.
>         
>         3.- Filters!!! The order of the filters does matter. :D the OSIV
>         MUST be mapped before the wicket filter. I thought that I knew
>         this but did it wrooong. Solved problem 3 -> put OSIV before any
>         other filter.
>         
>         
> With this everything backs to work. The only problem that I have to
> check now are transactions, and the order of doing things. Now object
> got loaded after model updates and it lost changes before saving. But
> the actual saving works. 
> 
> 
> Thank you all guys!!! 
> 
> Hope this e-mail serves as reference to others... :D
> 
> 
> 
> 
> 
> 
> 
> 
> El sáb, 04-06-2011 a las 07:27 -0400, James Carman escribió:
> > Can you try to replicate what you're doing in a more simple fashion?
> > Take your wicket framework code out of the mix.  Just try a
> > wicket/spring/hibernate example.  You can use the Wicketopia example
> > as a template if you want.
> > 
> > On Sat, Jun 4, 2011 at 6:01 AM, Gonzalo Aguilar Delgado
> > <ga...@aguilardelgado.com> wrote:
> > > I removed transactional pointcuts to see if this removes the issue.
> > >
> > > But the problem got worse. It seems that something is really wrong
> > > configured in my project.
> > >
> > > DEBUG - DefaultListableBeanFactory - Returning cached instance of
> > > singleton bean 'leadDAOBean'
> > > DEBUG - SessionFactoryUtils        - Opening Hibernate Session
> > > DEBUG - SessionImpl                - opened session at timestamp:
> > > 13071814596
> > > DEBUG - SessionFactoryUtils        - Closing Hibernate Session
> > > ERROR - RequestCycle               - Can't instantiate page using
> > > constructor public
> > > org.apache.wicket.examples.wscaffold.basicform.BasicFormPage()
> > > org.apache.wicket.WicketRuntimeException: Can't instantiate page using
> > > constructor public
> > > org.apache.wicket.examples.wscaffold.basicform.BasicFormPage()
> > >
> > > Watch this:
> > >  SessionFactoryUtils        - Opening Hibernate Session
> > >
> > > It seems that is not the OSIV filter. It's hibernate who opens the
> > > session. Why?
> > >
> > > It's strange because OSIV is configured:
> > > DEBUG - OpenSessionInViewFilter    - Initializing filter
> > > 'openSessionInViewFilter'
> > > DEBUG - OpenSessionInViewFilter    - Filter 'openSessionInViewFilter'
> > > configured successfully
> > >
> > > And the problem got worse without transactions:
> > >
> > > WicketMessage: Can't instantiate page using constructor public
> > > org.apache.wicket.examples.wscaffold.basicform.BasicFormPage()
> > >
> > > Root cause:
> > >
> > > org.hibernate.HibernateException: No Hibernate Session bound to thread,
> > > and configuration does not allow creation of non-transactional one here
> > >
> > > Not even the first page is instantiated...
> > >
> > > Will search more...
> > >
> > >
> > >
> > >
> > >
> > > El sáb, 04-06-2011 a las 11:28 +0200, Gonzalo Aguilar Delgado escribió:
> > >> >Hi,
> > >> >are you sure your model is a LDM?
> > >>
> > >> Yes. Sure. Encapsulated by an CompoundPropertyModel.
> > >> -------
> > >> new CompoundPropertyModel(scaffoldableModel)
> > >> -------
> > >> /*
> > >>                * Need this because wicket serializes everything and need to reload
> > >> it when
> > >>                * it's needed. This way wicket and hibernate plays well
> > >>                */
> > >>               IModel<Lead> scaffoldableModel = new
> > >> LoadableHibernateModelImpl<Lead>(getFirst())
> > >>               {
> > >>                       /**
> > >>                        *
> > >>                        */
> > >>                       private static final long serialVersionUID = 1L;
> > >>                       @SpringBean(name = "leadDAOBean")
> > >>                       private LeadDAO leadDAO;
> > >>                       private UuidUserType uuid;
> > >>
> > >>                       @Override
> > >>                       protected Lead load() {
> > >>                               Lead lead = null;
> > >>                               if(uuid!=null)
> > >>                               {
> > >>                                       lead = leadDAO.find(uuid);
> > >>
> > >>                               }
> > >>                               return lead;
> > >>                       }
> > >>
> > >>                       @Override
> > >>                       protected void setNonTransientObject() {
> > >>                               Lead lead =  this.getObject();
> > >>                               if(lead!=null)
> > >>                                       uuid = lead.getUuid();
> > >>                       }
> > >>
> > >>
> > >>               };
> > >>
> > >> --------
> > >> And...
> > >> ---------
> > >> public abstract class LoadableHibernateModelImpl<T> extends
> > >> LoadableDetachableModel<T>
> > >>       implements LoadableHibernateModel<T>, IModel<T>
> > >> ---------
> > >>
> > >> detach and load got called. So it's working. The problem seems to be
> > >> transactions.
> > >>
> > >> I used to reload the model in the onBeforeRender functions. This made
> > >> wicked open a transaction that continued until the save. But now I made
> > >> things different (more efficient). The problem now is how to get a
> > >> transaction run during the model update and save.
> > >>
> > >>
> > >>
> > >> >>IIRC you have a ListView involved. What's the type of
> > >> >>this.getDefaultModel() ?
> > >>
> > >> I checked this to make sure is the correct model. What I do is to set a
> > >> wrapper around. The component I use extends from panel and inside there
> > >> is a form and some other components that must use the model of the
> > >> panel. So I wrap it around with CompoundPropertyModel.
> > >>
> > >> ---------------
> > >>       public ScaffoldingForm(String id, IModel<T> scaffoldableModel) {
> > >>               //super(id, scaffoldableModel);
> > >>               super(id, new CompoundPropertyModel(scaffoldableModel));
> > >> ---------------
> > >>
> > >> The returning model is the CompoundPropertyModel. So seems to be ok.
> > >>
> > >>
> > >> Thank you in advance Sven.
> > >> I will try to make everything run in a unique transaction. I found this:
> > >> http://apache-wicket.1842946.n4.nabble.com/OpenSessionInView-OSIV-LoadableDetachableModel-and-Transactions-td1858513.html
> > >>
> > >> Maybe someone else have any other useful link.
> > >>
> > >> Thank you again.
> > >>
> > >>
> > >> ---------------------------------------------------------------------
> > >> 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
> > >
> > >
> > 
> > ---------------------------------------------------------------------
> > 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
> 


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