Re: Wicket & Jdbi & Guice
On Thu, Feb 7, 2019, 20:43 Vit Rozkovec Hi, thanks for comments. > > With supplier it works, but then in your code you need to have: > > @Inject > private IJdbiSupplier jdbiSupplier; > > ... > > Jdbi jdbi = jdbiSupplier.get(); > jdbi.useHandle(h->{ > ... > }); > > > which I wanted to avoid. > > > Would it be a solution to add a check to GuiceFieldValueFactory? > There is this code on line 86: > > if (wrapInProxies) > { > target = LazyInitProxyFactory.createProxy(field.getType(), locator); > } > > > I propose this change: > > |boolean isTransient = Modifier.isTransient(field.getModifiers());| > if (wrapInProxies && !isTransient) > { > target = LazyInitProxyFactory.createProxy(field.getType(), locator); > } > But if it is transient then it will be null after deserialization and lead to NullPointerExceptions. > > which I think is fine as there is no need for proxy as the field is not > serialized anyway. > > Then you can just do: > > @Inject > private transient Jdbi jdbi; > > ... > > jdbi.useHandle(h->{ > .. > }); > > > And as Jdbi is used as a singleton, this approach makes sense to me, am > I missing something? > > If you are fine with that, should I make a pull request? > > Adding Objenesis did not help. > > Thanks. > > Vit > > > On 2/7/19 7:45 AM, Martin Grigorov wrote: > > Hi, > > > > On Wed, Feb 6, 2019 at 7:55 PM Vit Rozkovec > wrote: > > > >> Hi, > >> > >> have any of you tried to inject Jdbi [1] via Guice to your component > >> hierarchy? I cannot do so without using intermediate Jdbi supplier. > >> > > Using supplier/provider is perfectly fine! > > > > > >> Please see this issue: > >> > >> https://github.com/jdbi/jdbi/issues/1451 > >> > >> I've tried to turn off wrapping in proxies for Guice, but it gives me: > >> > >> > org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream$ObjectCheckException: > >> The object type is not Serializable! > >> A problem occurred while checking object with type: > org.jdbi.v3.core.Jdbi > >> > > As you already know this is not good. The appication should not > > (de)serialize the Jdbi instance between requests. > > > > > >> with wrapInProxies set to true in GuiceComponentInjector the exception > is: > >> > >> java.lang.IllegalArgumentException: No visible constructors in class > >> org.jdbi.v3.core.Jdbi > >> > > You can try to add Objenesis to the classpath. LazyInitProxyFactory will > > use it instead of CGLIB if it is available. > > CGLIB requires the constructor. > > > > > >> I see where it comes from: LazyInitProxyFactory > >> > >> It seems to me that it is possible only to make happy Guice or Wicket, > >> but not both. > >> > > Just use supplier/provider! > > > > > >> Any hints appreciated. > >> > >> Thank you. > >> > >> Vit > >> > >> > >> [1] http://jdbi.org/ > >> > >> > >
Re: Wicket & Jdbi & Guice
Hi, thanks for comments. With supplier it works, but then in your code you need to have: @Inject private IJdbiSupplier jdbiSupplier; ... Jdbi jdbi = jdbiSupplier.get(); jdbi.useHandle(h->{ ... }); which I wanted to avoid. Would it be a solution to add a check to GuiceFieldValueFactory? There is this code on line 86: if (wrapInProxies) { target = LazyInitProxyFactory.createProxy(field.getType(), locator); } I propose this change: |boolean isTransient = Modifier.isTransient(field.getModifiers());| if (wrapInProxies && !isTransient) { target = LazyInitProxyFactory.createProxy(field.getType(), locator); } which I think is fine as there is no need for proxy as the field is not serialized anyway. Then you can just do: @Inject private transient Jdbi jdbi; ... jdbi.useHandle(h->{ .. }); And as Jdbi is used as a singleton, this approach makes sense to me, am I missing something? If you are fine with that, should I make a pull request? Adding Objenesis did not help. Thanks. Vit On 2/7/19 7:45 AM, Martin Grigorov wrote: Hi, On Wed, Feb 6, 2019 at 7:55 PM Vit Rozkovec wrote: Hi, have any of you tried to inject Jdbi [1] via Guice to your component hierarchy? I cannot do so without using intermediate Jdbi supplier. Using supplier/provider is perfectly fine! Please see this issue: https://github.com/jdbi/jdbi/issues/1451 I've tried to turn off wrapping in proxies for Guice, but it gives me: org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream$ObjectCheckException: The object type is not Serializable! A problem occurred while checking object with type: org.jdbi.v3.core.Jdbi As you already know this is not good. The appication should not (de)serialize the Jdbi instance between requests. with wrapInProxies set to true in GuiceComponentInjector the exception is: java.lang.IllegalArgumentException: No visible constructors in class org.jdbi.v3.core.Jdbi You can try to add Objenesis to the classpath. LazyInitProxyFactory will use it instead of CGLIB if it is available. CGLIB requires the constructor. I see where it comes from: LazyInitProxyFactory It seems to me that it is possible only to make happy Guice or Wicket, but not both. Just use supplier/provider! Any hints appreciated. Thank you. Vit [1] http://jdbi.org/
Re: Wicket & Jdbi & Guice
Hi, thanks for comments. With supplier it works, but then in your code you need to have: @Inject private IJdbiSupplier jdbiSupplier; ... Jdbi jdbi = jdbiSupplier.get(); jdbi.useHandle(h->{ ... }); which I wanted to avoid. Would it be a solution to add a check to GuiceFieldValueFactory? There is this code on line 86: if (wrapInProxies) { target = LazyInitProxyFactory.createProxy(field.getType(), locator); } I propose this change: |boolean isTransient = Modifier.isTransient(field.getModifiers());| if (wrapInProxies && !isTransient) { target = LazyInitProxyFactory.createProxy(field.getType(), locator); } which I think is fine as there is no need for proxy as the field is not serialized anyway. Then you can just do: @Inject private transient Jdbi jdbi; ... jdbi.useHandle(h->{ .. }); And as Jdbi is used as a singleton, this approach makes sense to me, am I missing something? If you are fine with that, should I make a pull request? Adding Objenesis did not help. Thanks. Vit On 2/7/19 7:45 AM, Martin Grigorov wrote: Hi, On Wed, Feb 6, 2019 at 7:55 PM Vit Rozkovec wrote: Hi, have any of you tried to inject Jdbi [1] via Guice to your component hierarchy? I cannot do so without using intermediate Jdbi supplier. Using supplier/provider is perfectly fine! Please see this issue: https://github.com/jdbi/jdbi/issues/1451 I've tried to turn off wrapping in proxies for Guice, but it gives me: org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream$ObjectCheckException: The object type is not Serializable! A problem occurred while checking object with type: org.jdbi.v3.core.Jdbi As you already know this is not good. The appication should not (de)serialize the Jdbi instance between requests. with wrapInProxies set to true in GuiceComponentInjector the exception is: java.lang.IllegalArgumentException: No visible constructors in class org.jdbi.v3.core.Jdbi You can try to add Objenesis to the classpath. LazyInitProxyFactory will use it instead of CGLIB if it is available. CGLIB requires the constructor. I see where it comes from: LazyInitProxyFactory It seems to me that it is possible only to make happy Guice or Wicket, but not both. Just use supplier/provider! Any hints appreciated. Thank you. Vit [1] http://jdbi.org/
Re: Wicket & Jdbi & Guice
Hi, On Wed, Feb 6, 2019 at 7:55 PM Vit Rozkovec wrote: > Hi, > > have any of you tried to inject Jdbi [1] via Guice to your component > hierarchy? I cannot do so without using intermediate Jdbi supplier. > Using supplier/provider is perfectly fine! > > Please see this issue: > > https://github.com/jdbi/jdbi/issues/1451 > > I've tried to turn off wrapping in proxies for Guice, but it gives me: > > org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream$ObjectCheckException: > The object type is not Serializable! > A problem occurred while checking object with type: org.jdbi.v3.core.Jdbi > As you already know this is not good. The appication should not (de)serialize the Jdbi instance between requests. > > with wrapInProxies set to true in GuiceComponentInjector the exception is: > > java.lang.IllegalArgumentException: No visible constructors in class > org.jdbi.v3.core.Jdbi > You can try to add Objenesis to the classpath. LazyInitProxyFactory will use it instead of CGLIB if it is available. CGLIB requires the constructor. > > I see where it comes from: LazyInitProxyFactory > > It seems to me that it is possible only to make happy Guice or Wicket, > but not both. > Just use supplier/provider! > > Any hints appreciated. > > Thank you. > > Vit > > > [1] http://jdbi.org/ > >