`
ninggy
  • 浏览: 112853 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

OpenJPA2.0.1一个疑问

阅读更多

最近在修改一个项目,有个问题困扰了很久一直没时间去解决。这次又在网上找了找,还是没有结果。闲话不多说了,错误代码:

 

<openjpa-2.0.1-r422266:989424 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:870)
	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:792)
	at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
	at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:288)
	at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:302)
	at org.apache.openjpa.persistence.QueryImpl.getSingleResult(QueryImpl.java:326)
	at com.strong.module.tjbqxh.service.ht.TJbqxhHTServiceXianShiImpl.getFenYe(TJbqxhHTServiceXianShiImpl.java:64)
	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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
	at $Proxy74.getFenYe(Unknown Source)
	at com.strong.module.tjbqxh.controller.ht.TJbqxhHTControllerXianShi.XianShiLieBiaoJSON(TJbqxhHTControllerXianShi.java:49)
	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.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:366)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
	at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
	at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
	at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
	at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
	at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
	at org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:91)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
	at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:167)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:550)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:380)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassCastException: org.apache.openjpa.util.IntId cannot be cast to [Ljava.lang.Object;
	at org.apache.openjpa.datacache.QueryCacheStoreQuery$CachedList.get(QueryCacheStoreQuery.java:505)
	at org.apache.openjpa.lib.rop.ListResultObjectProvider.getResultObject(ListResultObjectProvider.java:55)
	at org.apache.openjpa.kernel.QueryImpl$PackingResultObjectProvider.getResultObject(QueryImpl.java:2073)
	at org.apache.openjpa.kernel.QueryImpl.singleResult(QueryImpl.java:1325)
	at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1237)
	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1005)
	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:861)
	... 79 more

 出现原因描述:OpenJPA开启了缓存。如果设备(Sb)有个属性叫设备类型(Sblx)。他两是一对多的关系。单独分页查询设备类型没有问题。如果在添加设备的时候查询所有设备类型,也没有问题。但在去查询设备类型的时候就报上述错误。

挠头苦思半响,去掉缓存。居然就可以了。但是这样缓存用不上了,有点不心甘。最后发现。缓存开启、JPQL语句没有where条件的两个查询会出上述错误,select count(t) from TSblx  t(在分页查询时候要获取总数) 和 select t from TSblx t; 所以我就在查询所有设备类型时候多加个条件就可以了。

获取总数代码:

 

    EntityManager em = tsblxDAO.getEntityManager();
    CriteriaBuilder cb = em.getCriteriaBuilder();

    CriteriaQuery<Long> cq = cb.createQuery(Long.class);
    Root<TSblx> root = cq.from(TSblx.class);
    cq.select(cb.count(root));
    TypedQuery<Long> tq = em.createQuery(cq);
    tq.getSingleResult();

 查询所有代码:

 

    EntityManager em = tsblxDAO.getEntityManager();
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<TSblx> cq = cb.createQuery(TSblx.class);
    Root<TSblx> root = cq.from(TSblx.class);
    cq.select(root);
 //在这加个查询条件
    TypedQuery<TSblx> tq = em.createQuery(cq);
    return tq.getResultList();

 

另外可以在操作之前清空缓存:

 

 

    EntityManagerFactory emf = tsbDAO.getEntityManagerFactory();
    OpenJPAEntityManagerFactory oemf = OpenJPAPersistence.cast(emf);
    Cache qcache = oemf.getCache();
    qcache.evictAll();
 

 

分享到:
评论

相关推荐

    openjpa-2.0.1.jar

    OpenJPA聚合罐 org.apache.openjpa/openjpa/2.0.1/openjpa-2.0.1.jar

    Apache OpenJPA 2.1 User's Guide

    OpenJPA is Apache's implementation of Sun's Java Persistence 2.0 API (JSR-317 JPA 2.0) specification for the transparent persistence of Java objects. This document provides an overview of the JPA ...

    openjpa 写的一个例子

    自己用openjpa些的一个基于web 的例子

    openjpa范例及实例工程

    默认情况下,当应用程序第一次获取实体标识时,OpenJPA 框架从数据库中一次性获取 50 个连续的实体标识缓存起来,当下一次应用程序需要获取实体标识时,OpenJPA 将首先检测缓存中是否存在实体标识,如果存在,Open...

    OpenJPA 2.2.1 API (CHM格式)

    本地是指 JPA 应用中的 EntityManager 必须直接连接到指定的数据库,而且必须和使用它的代码在同一个 JVM 中。在线是指所有针对实体的操作必须在一个 EntityManager 范围中运行。这两个特征,加上 EntityManager ...

    openJPA官方手册

    openJPA官方手册,openJPA官方手册openJPA官方手册

    OpenJPA API 文档 chm格式

    OpenJPA API 文档 chm格式

    Open JPA2 employee 简单例子

    Open JPA2 employee 简单例子

    jsf、openJpa学习

    jsf 入门知识 ,jsf标签,jsf与openJpa整合,jsf与Spring整合

    Spring中使用OpenJPA

    Spring中使用OpenJPA源代码 博文链接:https://lxy19791111.iteye.com/blog/184997

    Spring MVC+OpenJPA框架

    Spring MVC+OpenJPA框架,只是个框架哦

    openjpa-manual

    JPA Overview and OpenJPA Reference Guide

    Openjpa手册

    OpenJPA OpenJPA 是 Apache 组织提供的开源项目,它实现了 EJB 3.0 中的 JPA 标准,为开发者提供功能强大、使用简单的持久化数据管理框架。

    openjpa:Apache OpenJPA

    Apache OpenJPA-自述文件 前言 感谢您下载此版本的Apache OpenJPA。 Apache OpenJPA是Java Persistence API规范的实现。 执照 此存储库的内容已根据Apache License 2.0 许可 更多信息 可以在openjpa-project子目录...

    Openjpa2.2+Mysql+Maven+Servlet+JSP source code

    Openjpa2.2+Mysql+Maven+Servlet+JSP 博客源码: http://blog.csdn.net/shenhonglei1234/article/details/10394379

    apache-openjpa-2.2.1-source

    OpenJPA 是 Apache 组织提供的开源项目,它实现了 EJB 3.0 中的 JPA 标准,为开发者提供功能强大、使用简单的持久化数据管理框架。OpenJPA 封装了和关系型数据库交互的操作,让开发者把注意力集中在编写业务逻辑上。...

    apache-openjpa-3.1.0-binary.zip

    JPA规范要求对实体对象...OpenJPA支持两种增强 方法,但强烈建议使用字节码编织增强。以下“ 实体增强” 页面包括有关两种增强类型的更多详细信息,以及有关如何在ANT,Maven和Eclipse环境中设置构建时间增强的示例。

    openjpa实体标识的生成策略

    本文是 使用 Apache OpenJPA 开发 EJB 3.0 应用系列 的第五部分,介绍在 OpenJPA 中如何自动生成实体的唯一标识,包括使用容器自动生成实体标识,借助于数据库的自动编号、序列号、数据库表等技术自动生成实体标识等...

    openjpa jar

    openjpa相关jar包,开发必备,希望对各位有帮助

    Spring和openJPA集成

    NULL 博文链接:https://laoli5290.iteye.com/blog/2088341

Global site tag (gtag.js) - Google Analytics