为什么这个代码在netbeans中抛出ClassCastException,而它在eclipse中正常运行

时间:2012-09-21 07:16:44

标签: java hibernate netbeans classcastexception runtimeexception

//运行时异常  在netbeans中调用以下代码时会发生运行时异常。在日食中工作得很好。

    public List<Ticket> findOpenTickets() {
            Session session = null;

            try {
                session = getSession();
                Criteria criteria = session.createCriteria(getReferenceClass());
                            criteria.add(Restrictions.eq(Ticket.PROP_CLOSED, Boolean.FALSE));
                List list = criteria.list();
                return list;
            } finally {
                closeSession(session);
            }
        }

异常堆栈跟踪是

java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.Short
at org.apache.derby.client.net.NetStatementRequest.buildFDODTA(Unknown Source)
at org.apache.derby.client.net.NetStatementRequest.buildSQLDTAcommandData(Unknown Source)
at org.apache.derby.client.net.NetStatementRequest.writeOpenQuery(Unknown Source)
at org.apache.derby.client.net.NetPreparedStatement.writeOpenQuery_(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.writeOpenQuery(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.flowExecute(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.executeQueryX(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.executeQuery(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at com.model.dao.TicketDAO.findOpenTickets(TicketDAO.java:154)
at com.util.TicketActiveDateSetterTask.run(TicketActiveDateSetterTask.java:29)
at com.main.Application.initDatabase(Application.java:160)
at com.main.Application.start(Application.java:91)
at com.main.Main.main(Main.java:12)

我无法解决此异常。因为一切似乎都很好,相同的代码在eclipse中正常运行但产生运行时异常。

1 个答案:

答案 0 :(得分:1)

检查你的hibernate.dialect是否正确?它一定是你的DB ..