在我们的应用程序中实现cqengine时,从AttributeByteCodeGenerator的createAttribute方法获取异常“ javassist.CannotCompileException:由java.lang.ClassFormatError:加载程序(sun / misc / Launcher $ AppClassLoader的实例):尝试重复的类定义”。 >
我们正在使用:
SQLParser<Order> parser = SQLParser.forPojoWithAttributes(Order.class,AttributeBytecodeGenerator.createAttributes(Order.class,MemberFilters.GETTER_METHODS_ONLY, AttributeNameProducers.USE_HUMAN_READABLE_NAMES_FOR_GETTERS));
服务等级代码:
public List<Order> getFilteredOrder() {
List<Order> orders = orderRepository.findAllByOrderByCreateTimeStampAsc();
IndexedCollection<Order> orderCollection = new ConcurrentIndexedCollection<>();
;
orderCollection.addAll(orders);
SQLParser<Order> parser = SQLParser.forPojoWithAttributes(Order.class,AttributeBytecodeGenerator.createAttributes(Order.class,MemberFilters.GETTER_METHODS_ONLY,
AttributeNameProducers.USE_HUMAN_READABLE_NAMES_FOR_GETTERS));
String query = "SELECT * FROM test_order WHERE customerId='12345' ORDER BY createTimeStamp ASC";
ResultSet<Order> resultSet=parser.retrieve(orderCollection, query);
List<Order> ordersList=resultSet.stream().parallel().collect(Collectors.toList());
return ordersList;
}
我的订单分类:
public class Order {
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
private String id;
@Column
private String customerId;
@Column
private String type;
@Column
private String productId;
@Column
private String status;
@Column(updatable = false)
private long createTimeStamp;
public static final Attribute<Order, String> custmerId = new SimpleAttribute<Order, String>("customerId") {
//public String getValue(Order user) { return user.customerId; }
@Override
public String getValue(Order arg0, QueryOptions arg1) {
return arg0.customerId;
}
};
@PrePersist
void onCreate() {
createTimeStamp = Instant.now().toEpochMilli();
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCustomerId() {
return customerId;
}
public void setCustomerId(String customerId) {
this.customerId = customerId;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public long getCreateTimeStamp() {
return createTimeStamp;
}
}
请注意,当我第一次调用getFilteredOrder()方法时,它可以正常工作。第二次,当我调用相同的方法时,出现以下错误:
java.lang.IllegalStateException: Failed to create attribute for member: public java.lang.String com.example.demo.model.Order.getId()
at com.googlecode.cqengine.codegen.AttributeBytecodeGenerator.createAttributes(AttributeBytecodeGenerator.java:162) ~[cqengine-3.4.0.jar:na]
at com.example.demo.service.OrderService.getFilteredOrder(OrderService.java:40) ~[classes/:na]
at com.example.demo.controller.OrderController.getOrders(OrderController.java:43) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_171]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_171]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_171]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) ~[spring-web-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) ~[spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:891) ~[spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) ~[spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) ~[spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) ~[spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:866) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:635) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851) [spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-embed-websocket-8.5.34.jar:8.5.34]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) [spring-web-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109) [spring-web-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) [spring-web-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) [spring-web-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498) [tomcat-embed-core-8.5.34.jar:8.5.34]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.34.jar:8.5.34]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_171]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_171]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.34.jar:8.5.34]
at java.lang.Thread.run(Unknown Source) [na:1.8.0_171]
Caused by: java.lang.IllegalStateException: Failed to generate attribute for class com.example.demo.model.Order, type java.lang.String, name 'id'
at com.googlecode.cqengine.codegen.AttributeBytecodeGenerator.generateSimpleAttribute(AttributeBytecodeGenerator.java:489) ~[cqengine-3.4.0.jar:na]
at com.googlecode.cqengine.codegen.AttributeBytecodeGenerator.generateSimpleNullableAttributeForGetter(AttributeBytecodeGenerator.java:276) ~[cqengine-3.4.0.jar:na]
at com.googlecode.cqengine.codegen.AttributeBytecodeGenerator.createAttributes(AttributeBytecodeGenerator.java:154) ~[cqengine-3.4.0.jar:na]
... 56 common frames omitted
Caused by: javassist.CannotCompileException: by java.lang.ClassFormatError: loader (instance of sun/misc/Launcher$AppClassLoader): attempted duplicate class definition for name: "com/example/demo/model/Order$$CQEngine_SimpleNullableAttribute_id"
at javassist.util.proxy.DefineClassHelper.toClass(DefineClassHelper.java:271) ~[javassist-3.25.0-GA.jar:na]
at javassist.ClassPool.toClass(ClassPool.java:1232) ~[javassist-3.25.0-GA.jar:na]
at javassist.CtClass.toClass(CtClass.java:1384) ~[javassist-3.25.0-GA.jar:na]
at com.googlecode.cqengine.codegen.AttributeBytecodeGenerator.generateSimpleAttribute(AttributeBytecodeGenerator.java:485) ~[cqengine-3.4.0.jar:na]
... 58 common frames omitted
Caused by: java.lang.ClassFormatError: loader (instance of sun/misc/Launcher$AppClassLoader): attempted duplicate class definition for name: "com/example/demo/model/Order$$CQEngine_SimpleNullableAttribute_id"
at javassist.util.proxy.DefineClassHelper$Java7.defineClass(DefineClassHelper.java:182) ~[javassist-3.25.0-GA.jar:na]
at javassist.util.proxy.DefineClassHelper.toClass(DefineClassHelper.java:260) ~[javassist-3.25.0-GA.jar:na]
... 61 common frames omitted
答案 0 :(得分:0)
您只需创建一次属性(或整个解析器),然后对其进行缓存,以便对所有请求使用相同的属性或解析器。
如果您仅打算使用SQL查询访问集合,最简单的选择就是缓存整个解析器。