Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems with class hierarchy on Guice object

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?

Is there any way (instantiating with Guice) to get the same superclass as with "new ()"?.

Thanks.

like image 806
André Salvati Avatar asked Dec 05 '25 20:12

André Salvati


1 Answers

Thanks to Stuart McCulloch, who helped me here

It's possible to disable AOP (using Guice whitout AOP) which gives me what I wanted (br.com.xxxxx.server.service.ObjectifyDao) (not tested)

But I want to have AOP on my toolkit, so I've solved by getting the TypeArguments from the proxy classes generated by Guice:

        clazz = (Class<T>) ((ParameterizedType) TypeLiteral.get(getClass()).getSupertype(ObjectifyDao.class).getType()).getActualTypeArguments()[0];
like image 62
André Salvati Avatar answered Dec 09 '25 18:12

André Salvati



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!