找不到类:无法加载com.microsoft.sqlserver.jdbc.Nanos

时间:2015-02-03 22:00:55

标签: java hibernate primefaces sql-server-2012 classnotfoundexception

我有一个看似非常奇怪的问题。我的应用程序运行得相当好,我正在优化它(我从其他开发人员继承)。

该项目使用Hibernate 4和MS SQL Server,并使用Primefaces在Tomcat 8上运行。我最近回去并开始使用延迟加载(之前的开发人员将所有延迟加载设置为false)与来自Primefaces的LazyDateModel并且已经有一些问题回到工作状态。其中大多数我可以自己解决,但这个让我难过。

    <query name="assayByLineAndDateRange">
            <![CDATA[from Assay a where a.line.number = :line and a.time >= :startDate 
                          and a.time < :endDate order by a.time DESC]]>
        </query>

上述HQL查询将导致ClassNotFoundException的最终com.microsoft.sqlserver.jdbc.Nanos,我已经验证它已存在于我的项目类路径中。

现在对于奇怪的部分:当我删除查询的and条件时,应用程序运行正常,如下所示:

<query name="assayByLineAndDateRange">
            <![CDATA[from Assay a where a.line.number = :line order by a.time DESC]]>
        </query>

当我在我的util类中调用query.iterate()并且我不明白为什么时会发生确切的问题。以下是相关代码的片段:

protected List<T> getList(Query query) {
    List<T> list = new ArrayList<T>();
    System.out.println("Query name: " + query.getQueryString());
    try {
        @SuppressWarnings("rawtypes")
        Iterator i = query.iterate();
        System.out.println("This line does not print");
        while(i.hasNext()) {
            list.add(getNext(i));
        }
        return list;
    } catch(Exception e) {
        System.out.println("CAUSE: " + e.getCause().toString());
        e.printStackTrace();
        return null;
    }

请注意,此代码完全适用于所有其他查询,包括使用and运算符的查询。

以下是来自Assay的映射文件的相关部分:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.app.gen.model.data.Assay" table="ASSAY" schema="GEN">
        <id name="id" type="java.lang.Long" unsaved-value="0">
            <column name="ID" precision="10" scale="0"/>
            <generator class="identity"/>
        </id>
        <property name="time" type="timestamp">
            <column name="TIME" not-null="true" unique="true"/>
        </property>
        <many-to-one name="line" class="com.app.gen.model.data.Line" cascade="none">
            <column name="LINE_ID" not-null="true"/>
        </many-to-one>
     </class>
</hibernate-mapping>

此外,我已经测试了参数以确保它们正确传递它们。最重要的是,在我实现延迟加载之前,此查询工作正常。以下是延迟加载到Primefaces DataTable中的重载load方法:

@Override
public List<Assay> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) {
    try { 
        if(null==lineAssays)
            lineAssays = new HashMap<Integer,List<Assay>>();
        if(null == lineAssays.get(getLineNumber())) {
            if(log.isDebugEnabled()) { log.debug("Fetching Line Assays..."); }
            List<Assay> assays = GenServiceFactory.create().fetchAssaysByLineAndDateRange(getLineNumber(), getStartDate(), getEndDate());
            lineAssays.put(getLineNumber(),assays);
        }
    } catch(Exception e) {
        System.out.println("AN ERROR OCCURED!");
        e.printStackTrace();
    }
    try {
        int numAssays = lineAssays.get(getLineNumber()).size();
        this.setRowCount(numAssays); 

        if(numAssays > pageSize) {
            try {
                return lineAssays.get(line).subList(first, first + pageSize);
            }
            catch(IndexOutOfBoundsException e) {
                return lineAssays.get(line).subList(first, first + (numAssays % pageSize));
            }
        }
        else {
            return lineAssays.get(line);
        }
    } catch(NullPointerException e1) {
        System.out.println("lineAssays is null");
    }
    return null;
}

以下是异常的堆栈跟踪:

DEBUG (2015-02-03 14:57:50) [http-apr-8080-exec-34] (LazyAssayLoader.java:72) - Fetching Line Assays...
Query name: 
        from Assay a where a.line.number = :line and a.time >= :startDate and a.time < :endDate order by a.time DESC

CAUSE: java.lang.ClassNotFoundException
java.lang.IllegalStateException: Can't overwrite cause with java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already.  Could not load com.microsoft.sqlserver.jdbc.Nanos.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
    at java.lang.Throwable.initCause(Throwable.java:457)
    at org.apache.catalina.loader.WebappClassLoader.checkStateForClassLoading(WebappClassLoader.java:1331)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1212)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1173)
    at com.microsoft.sqlserver.jdbc.TDSWriter.writeScaledTemporal(IOBuffer.java:4278)
    at com.microsoft.sqlserver.jdbc.TDSWriter.writeRPCDateTime2(IOBuffer.java:4184)
    at com.microsoft.sqlserver.jdbc.DTV$SendByRPCOp.sendTemporal(dtv.java:584)
    at com.microsoft.sqlserver.jdbc.DTV$SendByRPCOp.execute(dtv.java:356)
    at com.microsoft.sqlserver.jdbc.DTV.executeOp(dtv.java:1025)
    at com.microsoft.sqlserver.jdbc.DTV.sendByRPC(dtv.java:1116)
    at com.microsoft.sqlserver.jdbc.Parameter.sendByRPC(Parameter.java:660)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.sendParamsByRPC(SQLServerPreparedStatement.java:473)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doPrepExec(SQLServerPreparedStatement.java:628)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:400)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:350)
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1716)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:285)
    at org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:82)
    at org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:82)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:56)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:2040)
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1837)
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1816)
    at org.hibernate.loader.hql.QueryLoader.iterate(QueryLoader.java:518)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.iterate(QueryTranslatorImpl.java:399)
    at org.hibernate.engine.query.spi.HQLQueryPlan.performIterate(HQLQueryPlan.java:245)
    at org.hibernate.internal.SessionImpl.iterate(SessionImpl.java:1331)
    at org.hibernate.internal.QueryImpl.iterate(QueryImpl.java:68)
    at com.core.service.HibernateService$AbstractHQLQuery.getList(HibernateService.java:120)
    at com.core.service.HibernateService$AbstractHQLQuery.getList(HibernateService.java:138)
    at com.urenco.iphex.service.IphexService.fetchAssaysByLineAndDateRange(IphexService.java:77)
    at com.urenco.iphex.view.lazy.LazyAssayLoader.load(LazyAssayLoader.java:73)
    at org.primefaces.component.datatable.DataTable.loadLazyData(DataTable.java:731)
    at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:79)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:63)
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:47)
    at org.primefaces.component.panel.PanelRenderer.encodeContent(PanelRenderer.java:202)
    at org.primefaces.component.panel.PanelRenderer.encodeMarkup(PanelRenderer.java:119)
    at org.primefaces.component.panel.PanelRenderer.encodeEnd(PanelRenderer.java:56)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
    at org.primefaces.component.tabview.TabViewRenderer.encodeTabContent(TabViewRenderer.java:274)
    at org.primefaces.component.tabview.TabViewRenderer.encodeContents(TabViewRenderer.java:253)
    at org.primefaces.component.tabview.TabViewRenderer.encodeMarkup(TabViewRenderer.java:127)
    at org.primefaces.component.tabview.TabViewRenderer.encodeEnd(TabViewRenderer.java:71)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
    at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
    at com.sun.faces.renderkit.html_basic.CompositeRenderer.encodeChildren(CompositeRenderer.java:78)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
    at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
    at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:518)
    at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1612)
    at javax.faces.component.UIForm.visitTree(UIForm.java:371)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
    at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:376)
    at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:297)
    at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183)
    at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:981)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:409)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    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.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:616)
lineAssays is null
    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:534)
    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.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:277)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2381)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2370)
    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)
Caused by: java.lang.ClassNotFoundException
    at org.apache.catalina.loader.WebappClassLoader.checkStateForClassLoading(WebappClassLoader.java:1330)
    ... 103 more

对不起文字的墙,但非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

我认为ClassNotFoundException不是真正的问题。如果您在

的源代码中查看here(第1328行)
org.apache.catalina.loader.WebappClassLoader.checkStateForClassLoading

实际尝试加载类并没有失败,在加载类之前验证Web应用程序的当前状态时失败,所以异常有点误导。

真正的问题似乎是您的应用在加载数据时的状态无效。寻找有关该问题的更多信息是指Tomcat缓存旧版本应用程序代码的问题。不确定是否是这种情况,或者您是否尝试从干净状态重新启动服务器。至少你可能确定类加载不是真正的问题。