Discussion:
Lazy load exception wicket and hibernate
Mathias P.W Nilsson
2008-03-11 15:01:04 UTC
Permalink
Hi!

I'm using wicket with hibernate and spring. In my web.xml I have
OpenEntityManagerInViewFilter. But when trying to add a dataview to my
wicket page I get the org.hibernate.LazyInitializationException: could not
initialize proxy - the owning Session was closed. Anyone?
--
View this message in context: http://www.nabble.com/Lazy-load-exception-wicket-and-hibernate-tp15976668p15976668.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
James Carman
2008-03-11 15:05:06 UTC
Permalink
Post by Mathias P.W Nilsson
Hi!
I'm using wicket with hibernate and spring. In my web.xml I have
OpenEntityManagerInViewFilter. But when trying to add a dataview to my
wicket page I get the org.hibernate.LazyInitializationException: could not
initialize proxy - the owning Session was closed. Anyone?
Are you using a detachable model or is the entity being stored with
the page (serialized)?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
Mathias P.W Nilsson
2008-03-11 19:54:36 UTC
Permalink
Not exactly sure what you mean here since this is my first time trying wicket
and hibernate, spring.

I have spring annoted daos that I use myDao().getList(); returns a list that
has lazy object references.
When I try to evoke a method on the lazy object i get the exception. I have
solved i right now with DTO but it seam total meaningless to have dto when
all my entities can be used in the wicket page.
--
View this message in context: http://www.nabble.com/Lazy-load-exception-wicket-and-hibernate-tp15976668p15988359.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
James Carman
2008-03-11 19:56:27 UTC
Permalink
Show us some code, please. How are you setting things up?
Post by Mathias P.W Nilsson
Not exactly sure what you mean here since this is my first time trying wicket
and hibernate, spring.
I have spring annoted daos that I use myDao().getList(); returns a list that
has lazy object references.
When I try to evoke a method on the lazy object i get the exception. I have
solved i right now with DTO but it seam total meaningless to have dto when
all my entities can be used in the wicket page.
--
View this message in context: http://www.nabble.com/Lazy-load-exception-wicket-and-hibernate-tp15976668p15988359.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
cjlyth
2008-03-28 20:11:51 UTC
Permalink
I have been getting the same error. I feel like im missing something. Maybe I
am doing something horibly wrong but I haven't been able to figure out what
it is.

I am using spring 2.5, Wicket 1.3.2, and I have put the
OpenEntityManagerInViewFilter in my web xml. The filter is loading ok, im
not sure what to do next...

If anyone can help please let me know what you need to see. I even have an
example application i can upload.
I am using a DataView, I have tried to inject the spring beans into every
part (data provider, etc) and I always get the same result...
For now I will include the wicket stuff:


public class Home extends WebPage {
@SpringBean
private TestService testService;

public Home() {
init();
}

public Home(PageParameters parameters) {
super(parameters);
init();
}

private void init() {
add(new DataView("container", new ListOwnerProvider()) {
private static final long serialVersionUID = 1L;

@Override
protected void populateItem(Item item) {
/*ListOwner owner = (ListOwner)item.getModelObject();*/
item.add(new Label("name"));
item.add(new ListView("entries"){
private static final long serialVersionUID = 1L;

@Override
protected void populateItem(ListItem item) {
item.add(new Label("value"));
}
});
}
});
}

class ListOwnerProvider implements IDataProvider {

private static final long serialVersionUID = 1L;

@Override
public void detach() {


}

@Override
public Iterator iterator(int first, int count) {
return testService.getListOwners(first,count).iterator();
}

@Override
public IModel model(Object object) {

return new CompoundPropertyModel(new ListOwnerModel((ListOwner)object));
}

@Override
public int size() {
return testService.getListOwners().size();
}
}

class ListOwnerModel extends LoadableDetachableModel {
private static final long serialVersionUID = 1L;
private Integer id;

public ListOwnerModel(ListOwner listOwner) {
this.id = listOwner.getId();
}

@Override
protected Object load() {
return testService.getListOwner(id);
}
}
}
Post by Mathias P.W Nilsson
I'm using wicket with hibernate and spring. In my web.xml I have
OpenEntityManagerInViewFilter. But when trying to add a dataview to my
wicket page I get the org.hibernate.LazyInitializationException
--
View this message in context: http://www.nabble.com/Lazy-load-exception-wicket-and-hibernate-tp15976668p16361116.html
Sent from the Wicket - User mailing list archive at Nabble.com.
lars vonk
2008-03-29 11:15:02 UTC
Permalink
What is the order of the filters you defined in your filter-mapping element
in the web.xml. IIRC you should put the OpenEntityManagerInViewFilter
definition in the filter-mapping after the WicketFilter otherwise the
WicketFilter will come first.

Lars
Post by cjlyth
I have been getting the same error. I feel like im missing something. Maybe I
am doing something horibly wrong but I haven't been able to figure out what
it is.
I am using spring 2.5, Wicket 1.3.2, and I have put the
OpenEntityManagerInViewFilter in my web xml. The filter is loading ok, im
not sure what to do next...
If anyone can help please let me know what you need to see. I even have an
example application i can upload.
I am using a DataView, I have tried to inject the spring beans into every
part (data provider, etc) and I always get the same result...
public class Home extends WebPage {
@SpringBean
private TestService testService;
public Home() {
init();
}
public Home(PageParameters parameters) {
super(parameters);
init();
}
private void init() {
add(new DataView("container", new ListOwnerProvider()) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(Item item) {
/*ListOwner owner =
(ListOwner)item.getModelObject();*/
item.add(new Label("name"));
item.add(new ListView("entries"){
private static final long serialVersionUID = 1L;
@Override
protected void
populateItem(ListItem item) {
item.add(new
Label("value"));
}
});
}
});
}
class ListOwnerProvider implements IDataProvider {
private static final long serialVersionUID = 1L;
@Override
public void detach() {
}
@Override
public Iterator iterator(int first, int count) {
return testService.getListOwners
(first,count).iterator();
}
@Override
public IModel model(Object object) {
return new CompoundPropertyModel(new
ListOwnerModel((ListOwner)object));
}
@Override
public int size() {
return testService.getListOwners().size();
}
}
class ListOwnerModel extends LoadableDetachableModel {
private static final long serialVersionUID = 1L;
private Integer id;
public ListOwnerModel(ListOwner listOwner) {
this.id = listOwner.getId();
}
@Override
protected Object load() {
return testService.getListOwner(id);
}
}
}
Post by Mathias P.W Nilsson
I'm using wicket with hibernate and spring. In my web.xml I have
OpenEntityManagerInViewFilter. But when trying to add a dataview to my
wicket page I get the org.hibernate.LazyInitializationException
--
http://www.nabble.com/Lazy-load-exception-wicket-and-hibernate-tp15976668p16361116.html
Sent from the Wicket - User mailing list archive at Nabble.com.
Igor Vaynberg
2008-03-29 16:48:32 UTC
Permalink
erm, i thought filters were executed in the order they were defined in
web.xml. so open..inview should be declared before wicket. and its not
the filter-mapping but the filter element...

-igor
Post by lars vonk
What is the order of the filters you defined in your filter-mapping element
in the web.xml. IIRC you should put the OpenEntityManagerInViewFilter
definition in the filter-mapping after the WicketFilter otherwise the
WicketFilter will come first.
Lars
Post by cjlyth
I have been getting the same error. I feel like im missing something. Maybe I
am doing something horibly wrong but I haven't been able to figure out what
it is.
I am using spring 2.5, Wicket 1.3.2, and I have put the
OpenEntityManagerInViewFilter in my web xml. The filter is loading ok, im
not sure what to do next...
If anyone can help please let me know what you need to see. I even have an
example application i can upload.
I am using a DataView, I have tried to inject the spring beans into every
part (data provider, etc) and I always get the same result...
public class Home extends WebPage {
@SpringBean
private TestService testService;
public Home() {
init();
}
public Home(PageParameters parameters) {
super(parameters);
init();
}
private void init() {
add(new DataView("container", new ListOwnerProvider()) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(Item item) {
/*ListOwner owner =
(ListOwner)item.getModelObject();*/
item.add(new Label("name"));
item.add(new ListView("entries"){
private static final long
serialVersionUID = 1L;
@Override
protected void
populateItem(ListItem item) {
item.add(new
Label("value"));
}
});
}
});
}
class ListOwnerProvider implements IDataProvider {
private static final long serialVersionUID = 1L;
@Override
public void detach() {
}
@Override
public Iterator iterator(int first, int count) {
return testService.getListOwners
(first,count).iterator();
}
@Override
public IModel model(Object object) {
return new CompoundPropertyModel(new
ListOwnerModel((ListOwner)object));
}
@Override
public int size() {
return testService.getListOwners().size();
}
}
class ListOwnerModel extends LoadableDetachableModel {
private static final long serialVersionUID = 1L;
private Integer id;
public ListOwnerModel(ListOwner listOwner) {
this.id = listOwner.getId();
}
@Override
protected Object load() {
return testService.getListOwner(id);
}
}
}
Post by Mathias P.W Nilsson
I'm using wicket with hibernate and spring. In my web.xml I have
OpenEntityManagerInViewFilter. But when trying to add a dataview to my
wicket page I get the org.hibernate.LazyInitializationException
--
http://www.nabble.com/Lazy-load-exception-wicket-and-hibernate-tp15976668p16361116.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
lars vonk
2008-03-29 19:24:28 UTC
Permalink
They are initialized in the order they are defined, but executed in the
order of filter-mapping:

Quote from servlet spec 2.4:

The order the container uses in building the chain of filters to be applied
for a
1. First, the <url-pattern> matching filter mappings in the same order
that these
elements appear in the deployment descriptor.
I tested (in jetty) this to be sure and it's correct. So it's the
filter-mapping, not the filter definition.

Lars
erm, i thought filters were executed in the order they were defined in
web.xml. so open..inview should be declared before wicket. and its not
the filter-mapping but the filter element...
-igor
Post by lars vonk
What is the order of the filters you defined in your filter-mapping
element
Post by lars vonk
in the web.xml. IIRC you should put the OpenEntityManagerInViewFilter
definition in the filter-mapping after the WicketFilter otherwise the
WicketFilter will come first.
Lars
Post by cjlyth
I have been getting the same error. I feel like im missing something. Maybe I
am doing something horibly wrong but I haven't been able to figure
out
Post by lars vonk
Post by cjlyth
what
it is.
I am using spring 2.5, Wicket 1.3.2, and I have put the
OpenEntityManagerInViewFilter in my web xml. The filter is loading
ok, im
Post by lars vonk
Post by cjlyth
not sure what to do next...
If anyone can help please let me know what you need to see. I even
have an
Post by lars vonk
Post by cjlyth
example application i can upload.
I am using a DataView, I have tried to inject the spring beans into
every
Post by lars vonk
Post by cjlyth
part (data provider, etc) and I always get the same result...
public class Home extends WebPage {
@SpringBean
private TestService testService;
public Home() {
init();
}
public Home(PageParameters parameters) {
super(parameters);
init();
}
private void init() {
add(new DataView("container", new ListOwnerProvider())
{
Post by lars vonk
Post by cjlyth
private static final long serialVersionUID =
1L;
Post by lars vonk
Post by cjlyth
@Override
protected void populateItem(Item item) {
/*ListOwner owner =
(ListOwner)item.getModelObject();*/
item.add(new Label("name"));
item.add(new ListView("entries"){
private static final long
serialVersionUID = 1L;
@Override
protected void
populateItem(ListItem item) {
item.add(new Label("value"));
}
});
}
});
}
class ListOwnerProvider implements IDataProvider {
private static final long serialVersionUID = 1L;
@Override
public void detach() {
}
@Override
public Iterator iterator(int first, int count) {
return testService.getListOwners
(first,count).iterator();
}
@Override
public IModel model(Object object) {
return new CompoundPropertyModel(new
ListOwnerModel((ListOwner)object));
}
@Override
public int size() {
return testService.getListOwners().size();
}
}
class ListOwnerModel extends LoadableDetachableModel {
private static final long serialVersionUID = 1L;
private Integer id;
public ListOwnerModel(ListOwner listOwner) {
this.id = listOwner.getId();
}
@Override
protected Object load() {
return testService.getListOwner(id);
}
}
}
Post by Mathias P.W Nilsson
I'm using wicket with hibernate and spring. In my web.xml I have
OpenEntityManagerInViewFilter. But when trying to add a dataview to
my
Post by lars vonk
Post by cjlyth
Post by Mathias P.W Nilsson
wicket page I get the org.hibernate.LazyInitializationException
--
http://www.nabble.com/Lazy-load-exception-wicket-and-hibernate-tp15976668p16361116.html
Post by lars vonk
Post by cjlyth
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
Igor Vaynberg
2008-03-29 23:31:37 UTC
Permalink
thanks. i always thought it was the other way, probably because i
googled it at the time instead of reading the spec. if you google
"web.xml filter order" the first hit you get is

http://www.onjava.com/pub/a/onjava/2001/05/10/servlet_filters.html?page=3

which states that it is the order they are defined...


-igor
Post by lars vonk
They are initialized in the order they are defined, but executed in the
The order the container uses in building the chain of filters to be applied
for a
1. First, the <url-pattern> matching filter mappings in the same order
that these
elements appear in the deployment descriptor.
I tested (in jetty) this to be sure and it's correct. So it's the
filter-mapping, not the filter definition.
Lars
erm, i thought filters were executed in the order they were defined in
web.xml. so open..inview should be declared before wicket. and its not
the filter-mapping but the filter element...
-igor
Post by lars vonk
What is the order of the filters you defined in your filter-mapping
element
Post by lars vonk
in the web.xml. IIRC you should put the OpenEntityManagerInViewFilter
definition in the filter-mapping after the WicketFilter otherwise the
WicketFilter will come first.
Lars
Post by cjlyth
I have been getting the same error. I feel like im missing something.
Maybe I
am doing something horibly wrong but I haven't been able to figure
out
Post by lars vonk
Post by cjlyth
what
it is.
I am using spring 2.5, Wicket 1.3.2, and I have put the
OpenEntityManagerInViewFilter in my web xml. The filter is loading
ok, im
Post by lars vonk
Post by cjlyth
not sure what to do next...
If anyone can help please let me know what you need to see. I even
have an
Post by lars vonk
Post by cjlyth
example application i can upload.
I am using a DataView, I have tried to inject the spring beans into
every
Post by lars vonk
Post by cjlyth
part (data provider, etc) and I always get the same result...
public class Home extends WebPage {
@SpringBean
private TestService testService;
public Home() {
init();
}
public Home(PageParameters parameters) {
super(parameters);
init();
}
private void init() {
add(new DataView("container", new ListOwnerProvider())
{
Post by lars vonk
Post by cjlyth
private static final long serialVersionUID =
1L;
Post by lars vonk
Post by cjlyth
@Override
protected void populateItem(Item item) {
/*ListOwner owner =
(ListOwner)item.getModelObject();*/
item.add(new Label("name"));
item.add(new ListView("entries"){
private static final long
serialVersionUID = 1L;
@Override
protected void
populateItem(ListItem item) {
item.add(new
Label("value"));
}
});
}
});
}
class ListOwnerProvider implements IDataProvider {
private static final long serialVersionUID = 1L;
@Override
public void detach() {
}
@Override
public Iterator iterator(int first, int count) {
return testService.getListOwners
(first,count).iterator();
}
@Override
public IModel model(Object object) {
return new CompoundPropertyModel(new
ListOwnerModel((ListOwner)object));
}
@Override
public int size() {
return testService.getListOwners().size();
}
}
class ListOwnerModel extends LoadableDetachableModel {
private static final long serialVersionUID = 1L;
private Integer id;
public ListOwnerModel(ListOwner listOwner) {
this.id = listOwner.getId();
}
@Override
protected Object load() {
return testService.getListOwner(id);
}
}
}
Post by Mathias P.W Nilsson
I'm using wicket with hibernate and spring. In my web.xml I have
OpenEntityManagerInViewFilter. But when trying to add a dataview to
my
Post by lars vonk
Post by cjlyth
Post by Mathias P.W Nilsson
wicket page I get the org.hibernate.LazyInitializationException
--
http://www.nabble.com/Lazy-load-exception-wicket-and-hibernate-tp15976668p16361116.html
Post by lars vonk
Post by cjlyth
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
James Carman
2008-03-30 02:02:54 UTC
Permalink
Post by lars vonk
What is the order of the filters you defined in your filter-mapping element
in the web.xml. IIRC you should put the OpenEntityManagerInViewFilter
definition in the filter-mapping after the WicketFilter otherwise the
WicketFilter will come first.
I don't understand what you mean here. Are you saying that if I do this:

<filter-mapping>
<filter-name>oemiv</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>wicket</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

then the WicketFilter will execute first and the "oemiv" filter won't
ever execute?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
Igor Vaynberg
2008-03-30 02:14:12 UTC
Permalink
it will execute _after_ the wicket filter. which is no good because
you need lazy loading to work inside wicket filter, so you need oemiv
to execute before. and possibly, if wicket filter never calls
chain.dofilter it will never execute.

-igor


On Sat, Mar 29, 2008 at 7:02 PM, James Carman
Post by James Carman
Post by lars vonk
What is the order of the filters you defined in your filter-mapping element
in the web.xml. IIRC you should put the OpenEntityManagerInViewFilter
definition in the filter-mapping after the WicketFilter otherwise the
WicketFilter will come first.
<filter-mapping>
<filter-name>oemiv</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>wicket</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
then the WicketFilter will execute first and the "oemiv" filter won't
ever execute?
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
James Carman
2008-03-30 03:04:12 UTC
Permalink
Post by Igor Vaynberg
it will execute _after_ the wicket filter. which is no good because
you need lazy loading to work inside wicket filter, so you need oemiv
to execute before. and possibly, if wicket filter never calls
chain.dofilter it will never execute.
I mean, are you sure it will execute after? I just did a simple test:

public class Filter1 implements Filter
{
public void doFilter(ServletRequest servletRequest,
ServletResponse servletResponse, FilterChain filterChain) throws
IOException, ServletException
{
System.out.println("Entering Filter1...");
filterChain.doFilter(servletRequest, servletResponse);
System.out.println("Exiting Filter1...");
}
}

public class Filter2 implements Filter
{
public void doFilter(ServletRequest servletRequest,
ServletResponse servletResponse, FilterChain filterChain) throws
IOException, ServletException
{
System.out.println("Entering Filter2...");
filterChain.doFilter(servletRequest, servletResponse);
System.out.println("Exiting Filter2...");
}
}

<filter>
<filter-name>filter1</filter-name>
<filter-class>com.mycompany.Filter1</filter-class>
</filter>
<filter>
<filter-name>filter2</filter-name>
<filter-class>com.mycompany.Filter2</filter-class>
</filter>
<filter-mapping>
<filter-name>filter1</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>filter2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>wicket.myproject</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

When I access my HomePage, it prints out:

Entering Filter1...
Entering Filter2...
Exiting Filter2...
Exiting Filter1...

So, I think you just have it backwards. The
OpenEntityManagerInViewFilter should be mapped before the
WicketFilter.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
Igor Vaynberg
2008-03-30 06:17:10 UTC
Permalink
On Sat, Mar 29, 2008 at 8:04 PM, James Carman
Post by James Carman
So, I think you just have it backwards. The
OpenEntityManagerInViewFilter should be mapped before the
WicketFilter.
i dont know if my english is broken or what, but i believe that is
exactly what ive been saying all along...

-igor

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
lars vonk
2008-03-30 10:01:20 UTC
Permalink
IIRC you should put the OpenEntityManagerInViewFilter definition in the
filter-mapping after the WicketFilter otherwise the WicketFilter will come
first.
I of course meant *before the WicketFilter*, because like I stated later on
in the mail that it's the definition of the *filter-mapping* element that
depicts the order of execution. So we are all on the same page here :-).


Lars
On Sat, Mar 29, 2008 at 8:04 PM, James Carman
Post by James Carman
So, I think you just have it backwards. The
OpenEntityManagerInViewFilter should be mapped before the
WicketFilter.
i dont know if my english is broken or what, but i believe that is
exactly what ive been saying all along...
-igor
---------------------------------------------------------------------
James Carman
2008-03-30 11:37:31 UTC
Permalink
Post by lars vonk
IIRC you should put the OpenEntityManagerInViewFilter definition in the
filter-mapping after the WicketFilter otherwise the WicketFilter will come
first.
I of course meant *before the WicketFilter*, because like I stated later on
in the mail that it's the definition of the *filter-mapping* element that
depicts the order of execution. So we are all on the same page here :-).
Yes, that's what I was originally questioning. I figured it was a
typo, but I wanted to make sure, because I always thought it was the
other way around.

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

Loading...