CriteriaQuery 多选 - 运行时构造函数错误

CriteriaQuery multiselect - Runtime constructor error

我正在使用 CriteriaQuery 创建具有特定 class 类型的 TypedQuery。 我只需要 class 类型的几列。 我正在通过多选方法选择这些列,但我正在努力处理下面的 RuntimeException。 它是说系统无法对构造函数进行罚款。 但是,我创建了构造函数。

请给我关于这个问题的建议。

创建带条件的查询。

CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder();
CriteriaQuery<VwLocationBrief> criteriaQuery = criteriaBuilder.createQuery(VwLocationBrief.class);

Root<VwLocationBrief> root = (Root<VwLocationBrief>) criteriaQuery.from(VwLocati onBrief.class);
CriteriaHelper<VwLocationBrief> criteriaHelper = criteriaHelperFactory.newCriteriaHelper(criteriaBuilder, root);
criteriaHelper.ignoreCaseLike(CONTACT_NAME, locationAdvancedSearchCriteria.getContactName())
        .ignoreCaseEq(CONTACT_EMAIL, locationAdvancedSearchCriteria.getEmailaddress())
        .ignoreCaseLike(LOCATION_NAME2, locationAdvancedSearchCriteria.getLocationName())
        .ignoreCaseLike(UNIT_NAME, locationAdvancedSearchCriteria.getUnitName())
        .ignoreCaseLike(LOCATION_CODE, locationAdvancedSearchCriteria.getLocationCode())
        .ignoreCaseAndSpaceSuffixLike(POSTCODE, locationAdvancedSearchCriteria.getPostcode() != null ? locationAdvancedSearchCriteria.getPostcode().replaceAll(" ", "") : null)
        .orderBy(LOCATION_NAME2, CriteriaHelper.ASCENDING);

//Here are the columns that I want to select
**criteriaQuery.multiselect(
        root.get(ADDRESS_LINE1),
        root.get(ADDRESS_LINE2),
        root.get(ADDRESS_LINE3),
        root.get(ADDRESS_LINE5),
        root.get("businessName"),
        root.get(BRN_PARAM),        
        root.get(LOCATION_CODE),
        root.get("locationId"),
        root.get(LOCATION_NAME),
        root.get("mainLocation"),   
        root.get(POST_TOWN),
        root.get(POSTCODE))
.distinct(true);**

criteriaQuery.where(criteriaHelper.getPredicates());
if(type != null && type.equals("list")) {
    criteriaQuery.orderBy(criteriaHelper.getOrdering());
}

这是构造函数。

public VwLocationBrief(String addressLine1, String addressLine2,
            String addressLine3, String addressLine5, String businessName,
            long brn, String locationCode, long locationId,
            String locationName, boolean mainLocation, String postTown,
            String postcode) {
        this.addressLine1 = addressLine1;
        this.addressLine2 = addressLine2;
        this.addressLine3 = addressLine3;
        this.addressLine5 = addressLine5;
        this.businessName = businessName;
        this.brn = brn;
        this.locationCode = locationCode;
        this.locationId = locationId;
        this.locationName = locationName;
        this.mainLocation = mainLocation;
        this.postTown = postTown;
        this.postcode = postcode;
    }

这是我遇到的异常。

<openjpa-2.2.0-r422266:1244990 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Failed to execute query "null". Check the query syntax for correctness. See nested exception for details.
        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:872)
        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:794)
        at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
        at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:286)
        at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:302)
        at uk.gov.scotland.afrc.customer.service.entity.impl.LocationManagerImpl.locationAdvancedSearchCount(LocationManagerImpl.java:185)
        at entity.impl.LocationManagerImpl.locationAdvancedSearch(LocationManagerImpl.java:323)
        at Proxye7f1a3be_740d_413a_8d0e_b1416a65cdbc.locationAdvancedSearch(Unknown Source)
        at service.task.impl.LocationMaintenanceServiceImpl.locationAdvancedSearch(LocationMaintenanceServiceImpl.java:798)
        at Proxy3d258e3e_eb6f_4ca5_929d_23a654ac83a7.locationAdvancedSearch(Unknown Source)
        at Proxya98e61ee_2050_46bd_bcb5_7a21e398d8fd.locationAdvancedSearch(Unknown Source)
        at webservice.locationmaintenanceservice.impl.LocationMaintenanceServicePortImpl.locationAdvancedSearch(LocationMaintenanceServicePortImpl.java:295)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:180)
        at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
        at org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.invoke(AbstractJAXWSMethodInvoker.java:178)
        at org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:64)
        at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:75)
        at org.apache.cxf.interceptor.ServiceInvokerInterceptor.run(ServiceInvokerInterceptor.java:58)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
        at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
        at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:107)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
        at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
        at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:236)
        at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:214)
        at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:194)
        at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:130)
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:221)
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:141)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:713)
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:197)
        at sun.reflect.GeneratedMethodAccessor207.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.ops4j.pax.web.service.internal.HttpServiceStarted.invoke(HttpServiceStarted.java:182)
        at org.ops4j.pax.web.service.internal.$Proxy6.service(Unknown Source)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:652)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:447)
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:70)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:534)
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:227)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1038)
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:117)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:374)
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:189)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:972)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
        at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:75)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
        at org.eclipse.jetty.server.Server.handle(Server.java:363)
        at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:483)
        at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:931)
        at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:992)
        at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
        at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
        at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:51)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:543)
        at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.RuntimeException: Can not find constructor for "class model.domain.VwLocationBrief" with argument types "[class java.lang.String, class java.lang.String, class java.lang.String, class java.lang.String, class java.lang.String, long, class java.lang.String, long, class java.lang.String, boolean, class java.lang.String, class java.lang.String]" to fill d
        at org.apache.openjpa.kernel.FillStrategy$NewInstance.findConstructor(FillStrategy.java:139)
        at org.apache.openjpa.kernel.FillStrategy$NewInstance.fill(FillStrategy.java:144)
        at org.apache.openjpa.kernel.ResultShape.pack(ResultShape.java:362)
        at org.apache.openjpa.kernel.ResultShapePacker.pack(ResultShapePacker.java:64)
        at org.apache.openjpa.kernel.QueryImpl$PackingResultObjectProvider.getResultObject(QueryImpl.java:2082)
        at org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:36)
        at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1251)
        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1007)
        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:863)
        ... 67 more

我已经创建了构造函数。 现在有人可以告诉我这个 运行 时间错误是怎么回事吗?

您的多选选择的字段与您的构造函数所具有的不匹配。返回查询候选类型实例的一种更简单的方法是使用

criteriaQuery.select(root);

而不是criteriaQuery.multiselect(...)

我确认我的做法是正确的。 使用 CriteriaQuery.multiselect 时,我必须使用 select.

需要的字段创建构造函数

异常是 class 文件未被 Fuse 服务器读取的文件。 当我刷新我的环境时,它运行良好。

谢谢。