-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with generics #778
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I'm implementing a generic CRUD service, when I try to initiate the server I have this error
17:28:18.689 [main] INFO i.a.qbit.queue.impl.BasicQueue - Queue done creating Send Queue /services/cupones limit 100 checkEvery 10 tryTransfer falsepollTimeWait/polltime 15 17:28:18.689 [main] INFO i.a.q.service.impl.ServiceQueueImpl - Starting service cuponService 17:28:18.689 [main] INFO i.a.qbit.queue.impl.BasicQueue - Starting queue listener for Send Queue /services/cupones io.advantageous.qbit.service.impl.BaseServiceQueueImpl$3@51931956 17:28:18.689 [QueueListener|Send Queue booneventmanager] INFO i.a.q.b.events.impl.BoonEventManager - EventManagerQBIT_SYSTEM::joinService:: cuponService joined QBIT_SYSTEM Exception in thread "main" java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class at io.advantageous.qbit.meta.builder.ServiceMethodMetaBuilder.deduceReturnTypes(ServiceMethodMetaBuilder.java:164) at io.advantageous.qbit.meta.builder.ServiceMethodMetaBuilder.build(ServiceMethodMetaBuilder.java:139) at io.advantageous.qbit.meta.builder.ServiceMetaBuilder.addMethod(ServiceMetaBuilder.java:170) at io.advantageous.qbit.meta.builder.ServiceMetaBuilder.lambda$addMethods$97(ServiceMetaBuilder.java:116) at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) at io.advantageous.qbit.meta.builder.ServiceMetaBuilder.addMethods(ServiceMetaBuilder.java:116) at io.advantageous.qbit.meta.builder.ContextMetaBuilder.addService(ContextMetaBuilder.java:366) at io.advantageous.qbit.meta.builder.ContextMetaBuilder.addService(ContextMetaBuilder.java:377) at io.advantageous.qbit.server.HttpRequestServiceServerHandlerUsingMetaImpl.addRestSupportFor(HttpRequestServiceServerHandlerUsingMetaImpl.java:307) at io.advantageous.qbit.server.ServiceEndpointServerImpl.initServices(ServiceEndpointServerImpl.java:327) at io.advantageous.qbit.server.ServiceEndpointServerImpl.initServices(ServiceEndpointServerImpl.java:340) at com.fiveadvantages.chaos.server.Launcher.main(Launcher.java:23) 17:28:18.742 [QueueListener|Send Queue healthserviceimpl] INFO i.a.q.s.health.HealthServiceImpl - HealthService::register() CuponService 10000 MILLISECONDS
My generic service is :
`
import com.fiveadvantages.chaos.datalayer.dto.CuponDTO;
import com.fiveadvantages.chaos.datalayer.dto.DTO;
import com.fiveadvantages.chaos.datalayer.entity.Cupon;
import com.fiveadvantages.chaos.datalayer.entity.Entity;
import com.fiveadvantages.chaos.util.Util;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.DaoManager;
import com.j256.ormlite.jdbc.JdbcPooledConnectionSource;
import com.j256.ormlite.support.ConnectionSource;
import io.advantageous.boon.core.reflection.BeanUtils;
import io.advantageous.qbit.annotation.PathVariable;
import io.advantageous.qbit.annotation.RequestMapping;
import io.advantageous.qbit.annotation.RequestMethod;
import java.util.List;
public class GenericCRUDService<K extends Entity,T extends DTO,ID> {
private final static String DATABASE_URL = "jdbc:postgresql:https://localhost:5432/bd";
private final static String DATABASE_USER = "postgres";
private final static String DATABASE_PASSWORD = "********";
private K entity;
final Class entityClass;
private T DTO;
final Class dtoClass;
private Dao<K, ID> genericDAO;
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public CuponDTO getById(@PathVariable("id") ID id) {
ConnectionSource connectionSource = null;
CuponDTO cupon = new CuponDTO();
try {
connectionSource = new JdbcPooledConnectionSource ( DATABASE_URL,DATABASE_USER,DATABASE_PASSWORD);
genericDAO = DaoManager.createDao(connectionSource, entityClass);
BeanUtils.copyProperties(genericDAO.queryForId(id),cupon);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (connectionSource != null) {
try {
connectionSource.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return cupon;
}
}
`
The child Class is :
`import ch.qos.logback.classic.Logger;
import com.fiveadvantages.chaos.datalayer.dto.CuponDTO;
import com.fiveadvantages.chaos.datalayer.entity.Cupon;
import com.fiveadvantages.chaos.service.generic.GenericCRUDService;
import io.advantageous.qbit.annotation.RequestMapping;
import org.slf4j.LoggerFactory;
@RequestMapping("/cupones")
public class CuponService extends GenericCRUDService<Cupon,CuponDTO,Integer> {
}`
My pom.xml
`
4.0.0
`
The text was updated successfully, but these errors were encountered: