You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Neil McT <ne...@yahoo.co.uk> on 2008/10/29 15:44:16 UTC

LazyInit error with LDM in a panel

Hi,

I've got the above problem which I have boiled down to the following basic
example.....

MyPage references PanelA and PanelB which it swaps about depending on the
current state - both are created when the page is created but PanelA is
added to MyPage as the default display panel.

PanelB contains the following label...

add(new Label("testLabel", new PropertyModel(myLDM, "someCollection")));

myLDM is a LoadableDetachableModel which wraps a hibernate entity which, in
turn, has a 'someCollection' property.

On loading MyPage (first request), everything is fine (MyPage creates PanelA
and PanelB and displays PanelA). However on moving to PanelB (second
request) I get a LazyInitializationException saying that someCollection
couldn't be loaded.

I've already found a fix to this problem.... I delay the creation of the
panels until they are actually being used (i.e. on the call to
Panel.replaceWith()). However, I just can't really get my head around why
this fails in the first place. Basically why is the LDM not calling load()
on the second request?

Also, as the late-construction of the panels seems to work... is this what
people would recommend when swapping panels in and out of a page?

Any help much appreciated,

Neil.
-- 
View this message in context: http://www.nabble.com/LazyInit-error-with-LDM-in-a-panel-tp20228580p20228580.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: LazyInit error with LDM in a panel

Posted by Igor Vaynberg <ig...@gmail.com>.
that looks fine. is the myservice serializable? do you see any
serialization errors in the log.

if load() is not called then detach() is not called, that means you
are removing the model or the component that contains it after
getobject() has been called but before detach() was and you are
somehow holding onto this instance and giving it to the next panel...

-igor

On Wed, Oct 29, 2008 at 9:45 AM, Neil McT <ne...@yahoo.co.uk> wrote:
>
> Its probably not fool-proof, but it has worked fine up till now........
>
>
>
> public class MyLDM<T extends MyDomainModelIF> extends
> LoadableDetachableModel{
>
>        private MyServiceIF<T> modelLoaderService;
>        private Long id;
>
>        /**
>         * Constructor.
>         *
>         * @param object the model to make 'detachable'
>         * @param modelLoaderService used to load the model
>         */
>        public MyLDM(T object, MyServiceIF<T> modelLoaderService){
>        super(object);
>        this.modelLoaderService = modelLoaderService;
>                this.id = object.getId();
>        }
>
>        public MyLDM(Long id){
>                super();
>                this.id = id;
>        }
>
>        @Override
>        protected T load() {
>                return modelLoaderService.load(id);
>        }
>
>
>      public void setId(Long id) {
>          this.id = id;
>      }
>
>
>     @Override
>     @SuppressWarnings("unchecked")
>     public T getObject(){
>         return (T)super.getObject();
>     }
> }
>
> igor.vaynberg wrote:
>>
>> what is your ldm implementation look like?
>>
>> and yes, delayed construction is always the way to go.
>>
>> -igor
>>
>> On Wed, Oct 29, 2008 at 7:44 AM, Neil McT <ne...@yahoo.co.uk>
>> wrote:
>>
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/LazyInit-error-with-LDM-in-a-panel-tp20228580p20231137.html
> Sent from the Wicket - User mailing list archive at Nabble.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: LazyInit error with LDM in a panel

Posted by Neil McT <ne...@yahoo.co.uk>.
Its probably not fool-proof, but it has worked fine up till now........



public class MyLDM<T extends MyDomainModelIF> extends
LoadableDetachableModel{

	private MyServiceIF<T> modelLoaderService;
        private Long id;

	/**
	 * Constructor.
	 *
	 * @param object the model to make 'detachable'
         * @param modelLoaderService used to load the model
	 */
	public MyLDM(T object, MyServiceIF<T> modelLoaderService){
        super(object);
        this.modelLoaderService = modelLoaderService;
		this.id = object.getId();
	}

	public MyLDM(Long id){
		super();
		this.id = id;
	}

	@Override
	protected T load() {
   		return modelLoaderService.load(id);
	}

    
      public void setId(Long id) {
          this.id = id;
      }

   
     @Override
     @SuppressWarnings("unchecked")
     public T getObject(){
         return (T)super.getObject();
     }
}

igor.vaynberg wrote:
> 
> what is your ldm implementation look like?
> 
> and yes, delayed construction is always the way to go.
> 
> -igor
> 
> On Wed, Oct 29, 2008 at 7:44 AM, Neil McT <ne...@yahoo.co.uk>
> wrote:
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/LazyInit-error-with-LDM-in-a-panel-tp20228580p20231137.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: LazyInit error with LDM in a panel

Posted by Igor Vaynberg <ig...@gmail.com>.
what is your ldm implementation look like?

and yes, delayed construction is always the way to go.

-igor

On Wed, Oct 29, 2008 at 7:44 AM, Neil McT <ne...@yahoo.co.uk> wrote:
>
> Hi,
>
> I've got the above problem which I have boiled down to the following basic
> example.....
>
> MyPage references PanelA and PanelB which it swaps about depending on the
> current state - both are created when the page is created but PanelA is
> added to MyPage as the default display panel.
>
> PanelB contains the following label...
>
> add(new Label("testLabel", new PropertyModel(myLDM, "someCollection")));
>
> myLDM is a LoadableDetachableModel which wraps a hibernate entity which, in
> turn, has a 'someCollection' property.
>
> On loading MyPage (first request), everything is fine (MyPage creates PanelA
> and PanelB and displays PanelA). However on moving to PanelB (second
> request) I get a LazyInitializationException saying that someCollection
> couldn't be loaded.
>
> I've already found a fix to this problem.... I delay the creation of the
> panels until they are actually being used (i.e. on the call to
> Panel.replaceWith()). However, I just can't really get my head around why
> this fails in the first place. Basically why is the LDM not calling load()
> on the second request?
>
> Also, as the late-construction of the panels seems to work... is this what
> people would recommend when swapping panels in and out of a page?
>
> Any help much appreciated,
>
> Neil.
> --
> View this message in context: http://www.nabble.com/LazyInit-error-with-LDM-in-a-panel-tp20228580p20228580.html
> Sent from the Wicket - User mailing list archive at Nabble.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