org.hibernate.exception.JDBCConnectionException:无法加载实体:

时间:2014-12-31 06:16:21

标签: java mysql hibernate

我使用Hibernate将我的对象映射到MySql DB。当我在tomcat服务器上部署应用程序时,它工作正常,但是在一段不可预测的时间内发生一些异常情况。

任何帮助?

例外:

org.hibernate.exception.JDBCConnectionException: could not load an entity: [com.COMservices.hibernate.model.Relay#samsungs5]
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.loader.Loader.loadEntity(Loader.java:1874)
        at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
        at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
        at org.hibernate.loader.entity.BatchingEntityLoader.load(BatchingEntityLoader.java:82)
        at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3044)
        at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:395)
        at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)
        at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)
        at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:195)
        at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103)
        at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
        at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
        at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
        at com.COMservices.hibernate.dao.SignallingAgentDAO.getUserRouteDetails(SignallingAgentDAO.java:66)
        at com.signalingagent.fsm.SignalProcessEngine.run(SignalProcessEngine.java:221)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:679)
    Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
    Last packet sent to the server was 0 ms ago.
        at sun.reflect.GeneratedConstructorAccessor211.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:403)
        at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3136)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1834)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1976)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2503)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1737)
        at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1888)
        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.loadEntity(Loader.java:1860)
        ... 17 more
    Caused by: java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3121)
        ... 27 more

代码在这里:

  public void updateRouteDetails(String userid, String ipAddress, int port, int mode,String status) 
            {
             Transaction tx = null;
             Session sess = null;
             SessionFactory sf = null;
                    Relay rly = null;
                    try {
                        sf = HibernateUtil.getSessionFactory();
                        sess = sf.openSession();
                        sess.setFlushMode(FlushMode.COMMIT);
                        tx = sess.beginTransaction();
                        String uid = userid.toLowerCase().trim();
                        rly = (Relay) sess.get(Relay.class, uid);
                        if (rly != null) {
                            rly.setUserid(uid);
                            rly.setIp(ipAddress);
                            rly.setPort(port);
                            rly.setMode(mode);
                            rly.setDate(new Date());
                            sess.saveOrUpdate(rly);
                            tx.commit();
                        }
                    } catch (Exception e) {
                        if (tx != null) {
                            tx.rollback();
                        } finally  {
                        if (sess != null) {
                            sess.close();
                            sess = null;
                        }
                    }

        }

0 个答案:

没有答案