You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by William Speirs <ws...@apache.org> on 2014/02/27 05:10:20 UTC

Wicket + Guice + Transactional

I'm using guice-persist (
http://code.google.com/p/google-guice/wiki/GuicePersist) with Wicket and
trying to construct a SortableDataProvider that leverages Guice's
@Transactional annotation on the methods that read from the DB. In my page
I pass this SortableDataProvider to a DataTable which down the line sets a
field in a DataViewBase to this SortableDataProvider:

private final IDataProvider<T> dataProvider;

When Guice constructs this SortableDataProvider it rewrites (creates new?)
the class using CGLIB and adds a field of type
com.google.inject.internal.InterceptorStackCallback to my
SortableDataProvider. Unfortunately, this type is not Serializable and
looks like it never will be:
https://code.google.com/p/google-guice/issues/detail?id=12

I see a few options for "solving" this problem:

1) The IDataProvider<T> field in the DataViewBase could be marked as
transient getting around the issue that InterceptorStackCallback isn't
Serializable.

2) I can remove the @Transactional annotation from my methods. This way
Guice does NOT rewrite (create a new) class that adds an
InterceptorStackCallback field.

So my questions are:

1) What are the chances that DataViewBase could be updated to mark the
IDataProvider<T> field as transient?

2) Does anyone know the implications of NOT marking my methods as
@Transactional? I'm only doing SELECT statements in the code, and the
EntityManager is bound to the request. I'm just familiar enough with JPA
(Hibernate is my provider in this case) to be dangerous :-)

3) Is there anything else I can do?

Thanks!

Bill-

Re: Wicket + Guice + Transactional

Posted by "uwe@codesmell.de" <uw...@codesmell.de>.
On 03/01/2014 03:48 PM, William Speirs wrote:
> Does anyone have any thoughts on this?

guice-persist

https://code.google.com/p/google-guice/wiki/GuicePersist

cu uwe

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


Re: Wicket + Guice + Transactional

Posted by William Speirs <ws...@apache.org>.
Thanks for the idea... it worked! However the only hitch now is that I'm
force to use field injection which makes unit testing that much harder (I
really like everything constructor injected).

I guess what I'd need to do is have my Guice binding be to a @Provides
method which constructs a proxy class so that everything can be properly
injected and serialized. Any thoughts on how I'd go about doing that?

Bill-


On Sun, Mar 2, 2014 at 1:04 PM, uwe schaefer <uw...@codesmell.de> wrote:

>
> On 02.03.2014 14:51, Bill Speirs wrote:
>
>> field in the object. However it ONLY does this when I mark the methods as
>> @Transactional
>>
> yes, guice creates a proxy if it needs to (and it needs to if it needs to
> intercept the method call due to @Transactional).
> the point is here, try wrapping a wicket proxy around (or make the
> wicket-injector do the injection rather than guice itself), and your
> serialization problems are gone.
>
> cu uwe
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Wicket + Guice + Transactional

Posted by uwe schaefer <uw...@codesmell.de>.
On 02.03.2014 14:51, Bill Speirs wrote:
> field in the object. However it ONLY does this when I mark the methods as
> @Transactional
yes, guice creates a proxy if it needs to (and it needs to if it needs 
to intercept the method call due to @Transactional).
the point is here, try wrapping a wicket proxy around (or make the 
wicket-injector do the injection rather than guice itself), and your 
serialization problems are gone.

cu uwe

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


Re: Wicket + Guice + Transactional

Posted by Bill Speirs <bi...@gmail.com>.
I create the Dataprovider using Injection, which is why it creates the
InterceptorStackCallback
field in the object. However it ONLY does this when I mark the methods as
@Transactional

I don't think this is a Wicket proxy issue, more guice-persist. However, I
was wondering if anyone had ran into this issue before and what they did to
solve it.

Thanks...

Bill-

On Sat, Mar 1, 2014 at 10:13 AM, uwe@codesmell.de <uw...@codesmell.de> wrote:

> On 03/01/2014 03:48 PM, William Speirs wrote:
> >
> >> I'm using guice-persist
>
> how do you create the dataprovider? did you try to @inject a Provider<P>
> instead of P into your component?
> note that wicket proxies are just created for things injected by the
> framework into components.
>
> if you need to wrap something manually (discouraged, i guess) you can do
> smth along these lines:
>
> LazyInitProxyFactory.createProxy(Class<?> type, new
> IProxyTargetLocator(){... go to guice-injector and fetch the instance
> ... });
>
> or have a look at
>  org.apache.wicket.injection.Injector which you can grab by using
> Injector.get().inject(objectToInjectInto)
>
> which creates the necessary proxies.
>
> hope it helps,
>  uwe
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Wicket + Guice + Transactional

Posted by "uwe@codesmell.de" <uw...@codesmell.de>.
On 03/01/2014 03:48 PM, William Speirs wrote:
>
>> I'm using guice-persist

how do you create the dataprovider? did you try to @inject a Provider<P>
instead of P into your component?
note that wicket proxies are just created for things injected by the
framework into components.

if you need to wrap something manually (discouraged, i guess) you can do
smth along these lines:

LazyInitProxyFactory.createProxy(Class<?> type, new
IProxyTargetLocator(){... go to guice-injector and fetch the instance
... });

or have a look at
 org.apache.wicket.injection.Injector which you can grab by using
Injector.get().inject(objectToInjectInto)

which creates the necessary proxies.

hope it helps,
 uwe

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


Re: Wicket + Guice + Transactional

Posted by "uwe@codesmell.de" <uw...@codesmell.de>.
On 03/01/2014 03:48 PM, William Speirs wrote:
> Does anyone have any thoughts on this?

sorry for the last mail, prematurely sent.

uwe

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


Re: Wicket + Guice + Transactional

Posted by William Speirs <ws...@apache.org>.
Does anyone have any thoughts on this?

Thanks!

Bill-


On Wed, Feb 26, 2014 at 11:10 PM, William Speirs <ws...@apache.org> wrote:

> I'm using guice-persist (
> http://code.google.com/p/google-guice/wiki/GuicePersist) with Wicket and
> trying to construct a SortableDataProvider that leverages Guice's
> @Transactional annotation on the methods that read from the DB. In my page
> I pass this SortableDataProvider to a DataTable which down the line sets a
> field in a DataViewBase to this SortableDataProvider:
>
> private final IDataProvider<T> dataProvider;
>
> When Guice constructs this SortableDataProvider it rewrites (creates new?)
> the class using CGLIB and adds a field of type
> com.google.inject.internal.InterceptorStackCallback to my
> SortableDataProvider. Unfortunately, this type is not Serializable and
> looks like it never will be:
> https://code.google.com/p/google-guice/issues/detail?id=12
>
> I see a few options for "solving" this problem:
>
> 1) The IDataProvider<T> field in the DataViewBase could be marked as
> transient getting around the issue that InterceptorStackCallback isn't
> Serializable.
>
> 2) I can remove the @Transactional annotation from my methods. This way
> Guice does NOT rewrite (create a new) class that adds an
> InterceptorStackCallback field.
>
> So my questions are:
>
> 1) What are the chances that DataViewBase could be updated to mark the
> IDataProvider<T> field as transient?
>
> 2) Does anyone know the implications of NOT marking my methods as
> @Transactional? I'm only doing SELECT statements in the code, and the
> EntityManager is bound to the request. I'm just familiar enough with JPA
> (Hibernate is my provider in this case) to be dangerous :-)
>
> 3) Is there anything else I can do?
>
> Thanks!
>
> Bill-
>