从Web服务调用时导致问题的hibernate java.lang.ExceptionInInitializerError

时间:2015-07-17 05:13:07

标签: java hibernate

我使用netbeans对我的数据库进行逆向工程,并使用Web服务来访问某些信息。然而,Hibernate显示出一些问题。这是我第一次遇到这种问题。如果您能够确定问题所在。

以下是生成的代码和日志。

堆栈追踪:

Severe:   Initial SessionFactory creation failed.org.hibernate.MappingException: Could not instantiate persister org.hibernate.persister.entity.SingleTableEntityPersister
Severe:   java.lang.ExceptionInInitializerError
    at com.equiparco.cloud.hibernate.EquiParcoCloudHibernateUtil.<clinit>(EquiParcoCloudHibernateUtil.java:24)
    at com.equiparco.cloud.hibernate.helper.SysuserHelper.<init>(SysuserHelper.java:68)
    at com.equiparco.cloud.business.UserSessionControls.doLogin(UserSessionControls.java:75)
    at com.equiparco.cloud.business.UserSessionControls.loginUser(UserSessionControls.java:68)
    at com.equiparco.cloud.webservices.UserSessionService.loginToSystem(UserSessionService.java:24)
    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:497)
    at org.glassfish.webservices.InstanceResolverImpl$1.invoke(InstanceResolverImpl.java:144)
    at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:149)
    at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:88)
    at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:1136)
    at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:1050)
    at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:1019)
    at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:877)
    at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:136)
    at org.glassfish.webservices.MonitoringPipe.process(MonitoringPipe.java:142)
    at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:119)
    at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:1136)
    at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:1050)
    at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:1019)
    at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:877)
    at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:136)
    at com.sun.enterprise.security.webservices.CommonServerSecurityPipe.processRequest(CommonServerSecurityPipe.java:209)
    at com.sun.enterprise.security.webservices.CommonServerSecurityPipe.process(CommonServerSecurityPipe.java:141)
    at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:119)
    at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:1136)
    at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:1050)
    at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:1019)
    at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:877)
    at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:419)
    at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:868)
    at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:422)
    at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:169)
    at org.glassfish.webservices.JAXWSServlet.doPost(JAXWSServlet.java:169)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.hibernate.MappingException: Could not instantiate persister org.hibernate.persister.entity.SingleTableEntityPersister
    at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:174)
    at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:400)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
    at com.equiparco.cloud.hibernate.EquiParcoCloudHibernateUtil.<clinit>(EquiParcoCloudHibernateUtil.java:20)
    ... 65 more
Caused by: java.lang.ClassCastException: org.hibernate.type.StringType cannot be cast to org.hibernate.type.VersionType
    at org.hibernate.tuple.PropertyFactory.buildVersionProperty(PropertyFactory.java:181)
    at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:218)
    at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:520)
    at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:148)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
    ... 70 more

的HibernateUtil

package com.equiparco.cloud.hibernate;

import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.SessionFactory;

/**
 * Hibernate Utility class with a convenient method to get Session Factory
 * object.
 *
 * @author 
 */
public class EquiParcoCloudHibernateUtil {

    private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from standard (hibernate.cfg.xml) 
            // config file.
            sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Log the exception. 
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}

hibernate配置文件

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/equiparcocloud?zeroDateTimeBehavior=convertToNull</property>
    <property name="hibernate.connection.username">username</property>
    <property name="hibernate.connection.password">password</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.current_session_context_class">thread</property>
    <property name="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory</property>
    <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
    <property name="hibernate.c3p0.max_size">100</property>
    <property name="hibernate.c3p0.min_size">15</property>
    <property name="hibernate.c3p0.timeout">5000</property>
    <property name="hibernate.c3p0.max_statements">100</property>
    <property name="hibernate.c3p0.idle_test_period">300</property>
    <property name="hibernate.c3p0.acquire_increment">3</property>
    <property name="hibernate.cache.use_second_level_cache">false</property>
    <property name="hibernate.cache.use_query_cache">true</property>
    <property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</property>
    <mapping resource="com/equiparco/cloud/hibernate/pojoandmapping/FileShareToUser.hbm.xml"/>
    <mapping resource="com/equiparco/cloud/hibernate/pojoandmapping/ProjectDetailModHistory.hbm.xml"/>
    <mapping resource="com/equiparco/cloud/hibernate/pojoandmapping/BudgetRequest.hbm.xml"/>
    <mapping resource="com/equiparco/cloud/hibernate/pojoandmapping/Role.hbm.xml"/>
    <mapping resource="com/equiparco/cloud/hibernate/pojoandmapping/BudgetGrouping.hbm.xml"/>
    <mapping resource="com/equiparco/cloud/hibernate/pojoandmapping/ChartAccount.hbm.xml"/>
    <mapping resource="com/equiparco/cloud/hibernate/pojoandmapping/CloudPrintQueue.hbm.xml"/>
    <mapping resource="com/equiparco/cloud/hibernate/pojoandmapping/BudgetRequestItemList.hbm.xml"/>
    .....
  </session-factory>
</hibernate-configuration>

SysuserHelper.java

package com.equiparco.cloud.hibernate.helper;

/**
 *
 * @author 
 */

import com.equiparco.cloud.hibernate.EquiParcoCloudHibernateUtil;
import com.equiparco.cloud.hibernate.pojoandmapping.*;

import org.hibernate.Session;
import org.hibernate.Transaction;

import java.util.logging.Logger;
import java.util.ArrayList;

public class SysuserHelper {

    private final static Logger logger = Logger.getLogger(SysuserHelper.class.getName());

    Session session = null;

    Transaction trans;

    private Long savedId;
    private Sysuser savedTable;

    private Long totalRows;


    /**
     * 
     * @return 
     * 
     */
    public Long getSavedId() {
        return savedId;
    }

    /**
     * 
     * @param savedId 
     * 
     */
    public void setSavedId(Long savedId) {
        this.savedId = savedId;
    }

    public Sysuser getSavedTable() {
        return savedTable;
    }

    public void setSavedTable(Sysuser savedTable) {
        this.savedTable = savedTable;
    }

    public Long getTotalRows() {
        return totalRows;
    }

    public void setTotalRows(Long totalRows) {
        this.totalRows = totalRows;
    }

    public SysuserHelper(){
        logger.info("Helper Initializing (" + this.toString() + ").");
        try{

            this.session = EquiParcoCloudHibernateUtil.getSessionFactory().getCurrentSession();
            trans=session.beginTransaction();
        } catch(Exception ex){
            logger.severe("Error Found :" + ex.getMessage());
        }
    }

    public ArrayList<Sysuser> getData(String condition) {
        ArrayList<Sysuser> outList = null;
        try {
            String addQuery = "";
            if(!condition.isEmpty() && condition.length()>0) addQuery=" where " + condition;

            outList = (ArrayList<Sysuser>) session.createQuery("select from Sysuser" + addQuery).list();
        } catch (Exception ex) {
            String errMessage = "Error found: " + ex.getLocalizedMessage() + " - " + ex.getMessage();
            logger.warning(errMessage);
        }

        return outList;
    }

    public ArrayList<Sysuser> getData() {
        ArrayList<Sysuser> outList = null;
        try {
            outList = (ArrayList<Sysuser>) session.createQuery("select from Sysuser").list();
        } catch (Exception ex) {
            String errMessage = "Error found: " + ex.getLocalizedMessage() + " - " + ex.getMessage();
            logger.warning(errMessage);
        }

        return outList;
    }

0 个答案:

没有答案