On 26 Jun 2012, at 17:31, André Salvati wrote:

> Thanks Stuart.
> 
> I've tried to disable circular proxies this way and got same results.

Well circular proxies are only one of the possibilities I mentioned - the other 
is using AOP (such as method interception).

Based on the instance class name below (which has EnhancerByGuice) it looks 
like you, or something you're using, has enabled method interception for that 
class.
I'm guessing that it's related to guice-persist, which uses method interception 
to add transactional behaviour to classes or methods annotated with 
@Transactional.

If so then this is working-as-designed... in order to add the aspect behaviour 
the class must be extended, which will then add an extra class to the class 
hierarchy.

Is there a reason why you depend on a specific getGenericSuperclass? Usually 
such code can be improved to handle proxies by searching further up the 
hierarchy. 

> Is this the right way??
> 
>                               new ServletModule() {
> 
>                                       @Override
>                                       protected void configureServlets() {
>                                               
>                                               
> binder().disableCircularProxies();
> ...
>  
>                                               
> bind(EmpresaDao.class).in(RequestScoped.class)
> 
> 
> [INFO] new()
> [INFO] class -> class br.com.noxxonsat.server.service.EmpresaDao
> [INFO] superclass -> 
> br.com.noxxonsat.server.service.ObjectifyDao<br.com.noxxonsat.domain.Empresa>
> 
> [INFO] Guice
> [INFO] class -> class 
> br.com.noxxonsat.server.service.EmpresaDao$$EnhancerByGuice$$12c0765f
> [INFO] superclass -> class br.com.noxxonsat.server.service.EmpresaDao


> Em terça-feira, 26 de junho de 2012 10h25min44s UTC-3, Stuart McCulloch 
> escreveu:
> 
> On 26 Jun 2012, at 13:53, André Salvati wrote:
> 
>> I'm trying to use Guice to instantiate my Objectify DAOs. My hierarchy is 
>> the following:
>> 
>> public class EmpresaDao extends ObjectifyDao<Empresa> { ... }
>> 
>> public class ObjectifyDao<T> extends DAOBase { ... }
>> 
>> When I use "new EmpresaDao()", getClass().getGenericSuperclass() gives me:
>> 
>>     [INFO] superclass -> 
>> br.com.xxxxx.server.service.ObjectifyDao<br.com.xxxxx.domain.Empresa>
>> 
>> When I use "injector.getInstance(EmpresaDao.class)", 
>> getClass().getGenericSuperclass() gives me:
>> 
>>     [INFO] superclass -> class br.com.xxxx.server.service.EmpresaDao
>> 
>> Obviously, I want to let Guice instantiate my objects with DI.
>> 
>> Can someone explain why this is happen?
> 
> What does instance.getClass() show when using the injector?  If the name 
> contains "ByGuice" then Guice has created an intermediate proxy, which is why 
> the superclass differs.
> 
> Guice creates proxies to handle method interception (AOP) or to break 
> circular dependencies - you could try turning off the circular dependency 
> proxy feature in your module:
> 
>    
> http://google-guice.googlecode.com/git/javadoc/com/google/inject/Binder.html#disableCircularProxies()
> 
> or alternatively if you don't need AOP then you can use the "no_aop" flavour 
> of Guice. 
> 
>> Is there any way (instantiating with Guice) to get the same superclass as 
>> with new().
>> 
>> Thanks.
>> 
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "google-guice" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/google-guice/-/nD9OpdD__GEJ.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to 
>> [email protected].
>> For more options, visit this group at 
>> http://groups.google.com/group/google-guice?hl=en.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "google-guice" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/google-guice/-/c9TFlVtmfI0J.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/google-guice?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to