当Hibernate部署到tomcat服务器后尝试进行脏检查时,获取ClassCastException

时间:2018-07-12 08:50:29

标签: hibernate grails groovy gorm ggts

如果我没有正确地发布我的问题的应用程序。将应用程序部署到tomcat服务器时遇到了一个奇怪的问题,我得到了这个奇怪的ClassCastException布尔值,无法在.list()的末尾强制转换为BigDecimal。或.uniqueResult()。当我从GGTS(IDE)运行我的应用程序时,我没有面对它,仅当它在战争中部署到tomcat中时才会发生。 当我停止tomcat服务器并重新启动它时,这很奇怪,它的工作原理如何!但是每次我部署它时都会发生这种情况


  1. 休眠3.6.10最终版
  2. Grails 2.4.3
  3. Java jdk 1.8.25 谁能帮我。

下面是stacktrace和可重用的类

预先感谢

java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.math.BigDecimal
    at org.hibernate.type.descriptor.java.BigDecimalTypeDescriptor.areEqual(BigDecimalTypeDescriptor.java:36)
    at org.hibernate.type.AbstractStandardBasicType.isEqual(AbstractStandardBasicType.java:184)
    at org.hibernate.type.AbstractStandardBasicType.isSame(AbstractStandardBasicType.java:169)
    at org.hibernate.type.AbstractStandardBasicType.isDirty(AbstractStandardBasicType.java:214)
    at org.hibernate.type.AbstractStandardBasicType.isDirty(AbstractStandardBasicType.java:210)
    at org.hibernate.type.TypeHelper.findDirty(TypeHelper.java:295)
    at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:3404)
    at org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:520)
    at org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:230)
    at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:154)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
    at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:661)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:757)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:478)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:272)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)
    at jbilling.BreadcrumbService$$EnhancerBySpringCGLIB$$3475ee28.addBreadcrumb(<generated>)
    at jbilling.BreadcrumbService$addBreadcrumb$2.call(Unknown Source)
    at jbilling.CustomerController.show(CustomerController.groovy:556)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.codehaus.groovy.grails.web.servlet.mvc.MixedGrailsControllerHelper.invoke(MixedGrailsControllerHelper.java:154)
    at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.handleAction(AbstractGrailsControllerHelper.java:375)
    at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.executeAction(AbstractGrailsControllerHelper.java:252)
    at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.handleURI(AbstractGrailsControllerHelper.java:205)
    at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.handleURI(AbstractGrailsControllerHelper.java:126)
    at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.handleRequest(SimpleGrailsController.java:72)
    at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:50)
    at org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet.doDispatch(GrailsDispatcherServlet.java:347)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:721)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
    at org.codehaus.groovy.grails.web.mapping.UrlMappingUtils.forwardRequestForUrlMappingInfo(UrlMappingUtils.java:178)
    at org.codehaus.groovy.grails.web.mapping.UrlMappingUtils.forwardRequestForUrlMappingInfo(UrlMappingUtils.java:144)
    at org.codehaus.groovy.grails.web.mapping.UrlMappingUtils.forwardRequestForUrlMappingInfo(UrlMappingUtils.java:135)
    at org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter.doFilterInternal(UrlMappingsFilter.java:216)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at javax.servlet.FilterChain$doFilter.call(Unknown Source)
    at org.grails.plugin.resource.DevModeSanityFilter.doFilter(DevModeSanityFilter.groovy:45)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.authentication.switchuser.SwitchUserFilter.doFilter(SwitchUserFilter.java:181)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.java:53)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:146)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.java:82)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:69)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

BreadcrumService.groovy类

class BreadcrumbService implements InitializingBean, Serializable {

public static final String SESSION_BREADCRUMBS = "breadcrumbs"
public static final Integer MAX_ITEMS = 7
public static final Integer MAX_IN_STORE = MAX_ITEMS + 5

static scope = "session"

def void afterPropertiesSet() {
    load()
}

def void load() {
    if (session['user_id'])
        session[SESSION_BREADCRUMBS] = getBreadcrumbs()
}

/**
 * Returns a list of recorded breadcrumbs for the currently logged in user.
 *
 * @return list of recorded breadcrumbs.
 */

def Object getBreadcrumbs(int limit = MAX_ITEMS) {
    def userId = session["user_id"]
    def bred
    try{
        bred = Breadcrumb.withSession { session ->
        Query query = session.createQuery("from Breadcrumb b where b.userId = :userId order by b.id desc")
        query.setInteger("userId", userId)
        query.setReadOnly(true) //do not track entity changes
        query.setMaxResults(limit)
        query.setFlushMode(FlushMode.NEVER);
        query.list()

    }
    }catch(Exception e){
        log.error("Exception caught adding breadcrumb")
    }

    return bred
}

/**
 * It will delete breadcrumbs that belong to some user and have
 * less then or equal id to a given parameter. This method is used
 * to delete extra breadcrumbs that are no longer needed in database
 *
 * @param userId - the user id to which the breadcrumb belongs
 * @param firstInvalidId - the first invalid id
 * @return the number of deleted breadcrumbs
 */
def int deleteExtra(Integer userId, Long firstInvalidId) {
    return Breadcrumb.withSession { session ->
        Query query = session.createQuery("delete Breadcrumb b where b.userId = :userId and b.id <= :id")
        query.setInteger("userId", userId)
        query.setLong("id", firstInvalidId)
        query.setReadOnly(true) //do not track entity changes
        query.setFlushMode(FlushMode.NEVER);
        query.executeUpdate();
    }
}

/**
 * Returns the last recorded breadcrumb for the currently logged in user.
 *
 * @return last recorded breadcrumb.
 */
def Object getLastBreadcrumb() {
    return Breadcrumb.findByUserId(session['user_id'], [sort:'id', order:'desc'])
}

/**
 * Add a new breadcrumb to the breadcrumb list for the currently logged in user and
 * update the session list.
 *
 * The resulting breadcrumb link is generated using the 'g:link' grails tag. The same
 * parameter requirements for g:link apply here as well. A breadcrumb MUST have a controller,
 * but action and ID are optional. the name parameter is used to control the translated breadcrumb
 * message and is optional.
 *
 * @param controller breadcrumb controller (required)
 * @param action breadcrumb action, may be null
 * @param name breadcrumb message key name, may be null
 * @param objectId breadcrumb entity id, may be null.
 */
def void addBreadcrumb(String controller, String action, String name, Integer objectId) {
    name= StringUtils.abbreviate(name, 255);
    addBreadcrumb(new Breadcrumb(controller: controller, action: action, name: name, objectId: objectId))
}

def void addBreadcrumb(String controller, String action, String name, Integer objectId, String description) {
    name= StringUtils.abbreviate(name, 255);
    description= StringUtils.abbreviate(name, 255);
    addBreadcrumb(new Breadcrumb(controller: controller, action: action, name: name, objectId: objectId, description: description))
}

/**
 * Add a new breadcrumb to the recent breadcrumb list for the currently logged in user and
 * update the session list.
 *
 * @param crumb breadcrumb to add
 */
def void addBreadcrumb(Breadcrumb crumb) {
    def crumbs = getBreadcrumbs(MAX_IN_STORE)
    def lastItem = null
    if(crumbs != null){
        lastItem = !crumbs.isEmpty() ? crumbs.getAt(0) : null
    }

    // truncate string if its more than 255 words
    crumb.description = StringUtils.left(crumb.description, 255)

    // add breadcrumb only if it is different from the last crumb added
    try {
        if (!lastItem || !lastItem.equals(crumb)) {
            def userId = session['user_id']
            crumb.userId = userId
            crumb = crumb.save()

            crumbs.add(0, crumb)//ad as first, newest

            if (crumbs.size() > MAX_ITEMS) {
                def remove = crumbs.subList(MAX_ITEMS, crumbs.size())
                if (remove.size() >= (MAX_IN_STORE - MAX_ITEMS)) {
                    //we have reached the max breadcrumbs that
                    //we want to store in database per user
                    //so we will delete the extra elements
                    def firstInvalidId = remove.getAt(0).id
                    def deleteCount = deleteExtra(userId, firstInvalidId)
                    log.debug("Deleted: " + deleteCount + " breadcrumbs for user id: " + userId);
                }
                //removes the elements from original list as well
                remove.clear()
            }

            session[SESSION_BREADCRUMBS] = crumbs
        }

    } catch (Throwable t) {
        log.error("Exception caught adding breadcrumb", t)
        session.error = 'breadcrumb.failed'
    }
}

/**
 * Returns the HTTP session
 *
 * @return http session
 */
def HttpSession getSession() {
    return RequestContextHolder.currentRequestAttributes().getSession()
}

}

get Breadcrumb是由BreadcrumbService.groovy的addBreadcrumb方法调用的。

def Object getBreadcrumbs(int limit = MAX_ITEMS) {
    def userId = session["user_id"]
    def bred
    try{
        bred = Breadcrumb.withSession { session ->
        Query query = session.createQuery("from Breadcrumb b where b.userId = :userId order by b.id desc")
        query.setInteger("userId", userId)
        query.setReadOnly(true) //do not track entity changes
        query.setMaxResults(limit)
        query.setFlushMode(FlushMode.NEVER);
        query.list()

    }
    }catch(Exception e){
        log.error("Exception caught adding breadcrumb")
    }

    return bred
}

我的Breadcrumb.groovy域类

class Breadcrumb implements Serializable {

static transients = [ "messageCode" ]

static mapping = {
    id generator: 'org.hibernate.id.enhanced.TableGenerator',
       params: [
       table_name: 'jbilling_seqs',
       segment_column_name: 'name',
       value_column_name: 'next_id',
       segment_value: 'breadcrumb'
       ]
}

static constraints = {
    action(blank: true, nullable: true)
    name(blank: true, nullable: true , size:1..255)
    objectId(nullable: true)
    description(nullable: true, size:1..255)
}

Integer userId
String controller
String action
String name
Integer objectId
String description

def String getMessageCode() {
    StringBuilder builder = new StringBuilder();

    builder.append("breadcrumb")
    if (controller) builder.append('.').append(controller)
    if (action) builder.append('.').append(action)
    if (name) builder.append('.').append(name)
    if (!name && objectId) builder.append('.id')

   return builder.toString()
}

@Override
def boolean equals(o) {
    if (this.is(o)) return true;
    if (getClass() != o.class) return false;

    Breadcrumb that = (Breadcrumb) o;

    if (action != that.action) return false;
    if (controller != that.controller) return false;
    if (name != that.name) return false;
    if (objectId != that.objectId) return false;
    return true;
}

@Override
def int hashCode() {
    int result;

    result = controller.hashCode();
    result = 31 * result + (action != null ? action.hashCode() : 0);
    result = 31 * result + (name != null ? name.hashCode() : 0);
    result = 31 * result + (objectId != null ? objectId.hashCode() : 0);
    return result;
}

@Override
def String toString() {
    return "Breadcrumb{id=${id}, userId=${userId}, controller=${controller}, action=${action}, objectId=${objectId}, name=${name}, description=${description}}"
}
}

0 个答案:

没有答案