超出每个用户限制的会话

时间:2018-04-26 05:45:47

标签: java hibernate oracle11g

执行dao类代码的某些部分时,一旦执行输出,数据库ping失败就会显示在控制台中但不会显示在浏览器中。同时执行dao类代码的某些部分我是一旦我执行输出就会在控制台中显示数据库ping失败,但不会在浏览器中显示

如果我删除了getTransaction.commit(),它将显示输出但更新将不起作用。它获取upvote和downvotee的数量并显示它但是我再次点击它再次显示ping失败

这是错误

java.sql.SQLException: ORA-02391: exceeded simultaneous SESSIONS_PER_USER limit


at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:392)

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:385)

at oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:1018)

at oracle.jdbc.driver.T4CTTIoauthenticate.processError(T4CTTIoauthenticate.java:501)

at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:522)

at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:257)

at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:437)

at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:954)

at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:639)

at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:666)

at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)

at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:566)

at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.createConnection(JDBCConnection.java:328)

at org.eclipse.datatools.connectivity.DriverConnectionBase.internalCreateConnection(DriverConnectionBase.java:105)

at org.eclipse.datatools.connectivity.DriverConnectionBase.open(DriverConnectionBase.java:54)

at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.open(JDBCConnection.java:96)

at org.eclipse.datatools.enablement.internal.oracle.JDBCOracleConnectionFactory.createConnection(JDBCOracleConnectionFactory.java:27)

at org.eclipse.datatools.connectivity.internal.ConnectionFactoryProvider.createConnection(ConnectionFactoryProvider.java:83)

at org.eclipse.datatools.connectivity.internal.ConnectionProfile.createConnection(ConnectionProfile.java:359)

at org.eclipse.datatools.connectivity.ui.PingJob.createTestConnection(PingJob.java:76)

at org.eclipse.datatools.connectivity.ui.PingJob.run(PingJob.java:59)

at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

,我的dao类是

public class TagDAOImpl implements TagDAO {

@SuppressWarnings("unchecked")
public Map<Integer, String> viewQuestion(String question) throws Exception {
    Map<Integer, String> quesString = null;
    SessionFactory sessionFactory = null;
    Session session = null;
    List<QuestionEntity> custList = new ArrayList<QuestionEntity>();
    try {
        quesString = new LinkedHashMap<Integer, String>();
        sessionFactory = HibernateUtility.createSessionFactory();
        session = sessionFactory.openSession();
        QuestionEntity tag = new QuestionEntity();
        // Question q=new Question();
        // q.setTagId(question);
        // ques.setQuestionString(question.getQuestionString());
        System.out.println("dao" + question);

        // session.persist(ques);

        // session.getTransaction().begin();

        Query query = session
                .createQuery("from QuestionEntity where tagId=?");
        query.setString(0, question);
        custList = query.list();
        System.out.println(custList.size());
        // List list = query.list();
        for (QuestionEntity tagEntity : custList) {
            System.out
                    .println("Question ID=>" + tagEntity.getQuestionId()
                            + "\nQuestion String=>"
                            + tagEntity.getQuestionString());
            // List<String> newList = new ArrayList<String>();
            Question q = new Question();
            q.setQuestionId(tagEntity.getQuestionId());
            q.setQuestionString(tagEntity.getQuestionString());
            // newList.addAll(getTag(tagEntity.getQuestionId()));
            // String a=String.valueOf(tagEntity.getQuestionId());
            quesString.put(q.getQuestionId(), q.getQuestionString());

            // quesString.add(a);
            // quesString.addAll(newList);

        }
        // session.getTransaction().commit();

    } catch (HibernateException exception) {
        exception.printStackTrace();
        DOMConfigurator.configure("src/com/infy/resources/log4j.xml");
        Logger logger = Logger.getLogger(this.getClass());
        logger.error(exception.getMessage(), exception);
        throw new Exception("DAO.TECHNICAL_ERROR");
    } catch (Exception exception) {
        exception.printStackTrace();
        DOMConfigurator.configure("src/com/infy/resources/log4j.xml");
        Logger logger = Logger.getLogger(this.getClass());
        logger.error(exception.getMessage(), exception);
        throw exception;
    } finally {
        if (session.isOpen() || session != null) {
            session.close();
        }
    }
    return quesString;
}

// quesString.add();

// quesString.add("\n");

@SuppressWarnings({ "unchecked", "unused" })
public Map<Integer, String> getAnswer(Integer question) throws Exception {
    Map<Integer, String> quesString = null;
    SessionFactory sessionFactory = null;
    Session session = null;
    List<AnswerEntity> custList1 = new ArrayList<AnswerEntity>();
    try {
        quesString = new LinkedHashMap<Integer, String>();
        sessionFactory = HibernateUtility.createSessionFactory();
        session = sessionFactory.openSession();
        AnswerEntity tag = new AnswerEntity();
        // Question q=new Question();
        // q.setTagId(question);
        // ques.setQuestionString(question.getQuestionString());
        System.out.println("dao" + question);

        // session.persist(ques);

        // session.getTransaction().begin();
        System.out.println("before query exec");
        Query query = session
                .createQuery("from AnswerEntity where questionId=?");
        query.setInteger(0, question);
        System.out.println(query);
        System.out.println("after query exec");
        custList1 = query.list();
        System.out.println(custList1.size());
        // List list = query.list();
        for (AnswerEntity tagEntity : custList1) {
            // System.out.println("Question ID=>"+tagEntity.getQuestionId()+"\nQuestion String=>"+tagEntity.getQuestionString());
            // List<String> newList = new ArrayList<String>();
            Answer a = new Answer();
            a.setQuestionId(tagEntity.getQuestionId());
            a.setAnswerString(tagEntity.getAnswerString());
            // newList.addAll(getTag(tagEntity.getQuestionId()));
            // String a=String.valueOf(tagEntity.getQuestionId());
            quesString.put(a.getQuestionId(), a.getAnswerString());

            // quesString.add(a);
            // quesString.addAll(newList);

        }
        // session.getTransaction().commit();

    } catch (HibernateException exception) {
        exception.printStackTrace();
        DOMConfigurator.configure("src/com/infy/resources/log4j.xml");
        Logger logger = Logger.getLogger(this.getClass());
        logger.error(exception.getMessage(), exception);
        throw new Exception("DAO.TECHNICAL_ERROR");
    } catch (Exception exception) {
        exception.printStackTrace();
        DOMConfigurator.configure("src/com/infy/resources/log4j.xml");
        Logger logger = Logger.getLogger(this.getClass());
        logger.error(exception.getMessage(), exception);
        throw exception;
    } finally {
        if (session.isOpen() || session != null) {
            session.close();
        }
    }
    return quesString;
}

public Map<Integer, String> getAllQuestions() throws Exception {
    Map<Integer, String> quesString = null;
    SessionFactory sessionFactory = null;
    Session session = null;
    List<QuestionEntity> custList = new ArrayList<QuestionEntity>();
    try {
        quesString = new LinkedHashMap<Integer, String>();
        sessionFactory = HibernateUtility.createSessionFactory();
        session = sessionFactory.openSession();
        QuestionEntity tag = new QuestionEntity();
        // Question q=new Question();
        // q.setTagId(question);
        // ques.setQuestionString(question.getQuestionString());
        // System.out.println("dao"+question);

        // session.persist(ques);

        // session.getTransaction().begin();

        Query query = session.createQuery("from QuestionEntity");
        // query.setString(0, question);
        custList = query.list();
        System.out.println(custList.size());
        // List list = query.list();
        for (QuestionEntity tagEntity : custList) {
            System.out
                    .println("Question ID=>" + tagEntity.getQuestionId()
                            + "\nQuestion String=>"
                            + tagEntity.getQuestionString());
            // List<String> newList = new ArrayList<String>();
            Question q = new Question();
            q.setQuestionId(tagEntity.getQuestionId());
            q.setQuestionString(tagEntity.getQuestionString());
            // newList.addAll(getTag(tagEntity.getQuestionId()));
            // String a=String.valueOf(tagEntity.getQuestionId());
            quesString.put(q.getQuestionId(), q.getQuestionString());

            // quesString.add(a);
            // quesString.addAll(newList);

        }
        // session.getTransaction().commit();

    } catch (HibernateException exception) {
        exception.printStackTrace();
        DOMConfigurator.configure("src/com/infy/resources/log4j.xml");
        Logger logger = Logger.getLogger(this.getClass());
        logger.error(exception.getMessage(), exception);
        throw new Exception("DAO.TECHNICAL_ERROR");
    } catch (Exception exception) {
        exception.printStackTrace();
        DOMConfigurator.configure("src/com/infy/resources/log4j.xml");
        Logger logger = Logger.getLogger(this.getClass());
        logger.error(exception.getMessage(), exception);
        throw exception;
    } finally {
        if (session.isOpen() || session != null) {
            session.close();
        }
    }
    return quesString;
}

@SuppressWarnings("unchecked")
public Map<Integer, String> count(String tagged) throws Exception {
    Map<Integer, String> quesString = null;
    SessionFactory sessionFactory = null;
    Session session = null;
    List<QuestionEntity> custList = new ArrayList<QuestionEntity>();
    try {
        quesString = new LinkedHashMap<Integer, String>();
        sessionFactory = HibernateUtility.createSessionFactory();
        session = sessionFactory.openSession();
        QuestionEntity tag = new QuestionEntity();
        // Question q=new Question();
        // q.setTagId(question);
        // ques.setQuestionString(question.getQuestionString());
        // System.out.println("dao"+question);

        // session.persist(ques);

        // session.getTransaction().begin();

        Query query = session
                .createQuery("from QuestionEntity where tagId=?");
        query.setString(0, tagged);
        custList = query.list();
        System.out.println(custList.size());
        quesString.put(custList.size(), tagged);

        // session.getTransaction().commit();

    } catch (HibernateException exception) {
        exception.printStackTrace();
        DOMConfigurator.configure("src/com/infy/resources/log4j.xml");
        Logger logger = Logger.getLogger(this.getClass());
        logger.error(exception.getMessage(), exception);
        throw new Exception("DAO.TECHNICAL_ERROR");
    } catch (Exception exception) {
        exception.printStackTrace();
        DOMConfigurator.configure("src/com/infy/resources/log4j.xml");
        Logger logger = Logger.getLogger(this.getClass());
        logger.error(exception.getMessage(), exception);
        throw exception;
    } finally {
        if (session.isOpen() || session != null) {
            session.close();
        }
    }
    return quesString;
}

public List<String> getTag(Integer question) throws Exception {
    List<String> quesString = null;
    SessionFactory sessionFactory = null;
    Session session = null;

    try {
        quesString = new ArrayList<String>();
        sessionFactory = HibernateUtility.createSessionFactory();
        session = sessionFactory.openSession();
        QuestionEntity tag = new QuestionEntity();
        // Question q=new Question();
        // q.setTagId(question);
        // ques.setQuestionString(question.getQuestionString());
        System.out.println("dao" + question);

        // session.persist(ques);

        // session.getTransaction().begin();

        Query query2 = session
                .createQuery("from QuestionEntity where questionId=?");
        query2.setInteger(0, question);
        List<QuestionEntity> tagList = query2.list();
        for (QuestionEntity tagEntity : tagList)
            System.out.println("custlist " + tagEntity.getTagId());

        // List list = query2.list();
        for (QuestionEntity tagEntity : tagList) {
            System.out.println("Question ID=>" + tagEntity.getQuestionId()
                    + "\nQuestion String=>" + tagEntity.getQuestionString()
                    + "\ntagId=>" + tagEntity.getTagId());
            quesString.add(tagEntity.getTagId());
            System.out.println(tagEntity.getTagId());

        }
        // session.getTransaction().commit();

        // quesString.add();

        // quesString.add("\n");

    } catch (HibernateException exception) {
        exception.printStackTrace();
        DOMConfigurator.configure("src/com/infy/resources/log4j.xml");
        Logger logger = Logger.getLogger(this.getClass());
        logger.error(exception.getMessage(), exception);
        throw new Exception("DAO.TECHNICAL_ERROR");
    } catch (Exception exception) {
        exception.printStackTrace();
        DOMConfigurator.configure("src/com/infy/resources/log4j.xml");
        Logger logger = Logger.getLogger(this.getClass());
        logger.error(exception.getMessage(), exception);
        throw exception;
    } finally {
        if (session.isOpen() || session != null) {
            session.close();
        }
    }
    return quesString;
}

@Override
public Integer upvote(Integer questionId) throws Exception {
    SessionFactory sessionFactory = null;
    Session session = null;
    Integer updatedUpvote = null;
    try {
        sessionFactory = HibernateUtility.createSessionFactory();
        session = sessionFactory.openSession();
        System.out.println("key in like dao" + questionId);
        QuestionEntity qe = (QuestionEntity) session.get(
                QuestionEntity.class, questionId);
        if (qe != null) {
            // session.getTransaction().begin();
            updatedUpvote = qe.getUpvotes() + 1;
            System.out.println(updatedUpvote);
            qe.setUpvotes(updatedUpvote);
            System.out.println(qe.getUpvotes() + "entity");
            session.update(qe);
            session.getTransaction().commit();

        }
    } catch (HibernateException exception) {
        throw new Exception("DAO.TECHNICAL_ERROR");
    } catch (Exception exception) {
        throw exception;
    } finally {
        if (session.isOpen() || session != null) {
            session.close();
        }
    }
    return updatedUpvote;
}

@Override
public Integer downvote(Integer questionId) throws Exception {
    SessionFactory sessionFactory = null;
    Session session = null;
    Integer updatedDownvote = null;
    try {
        sessionFactory = HibernateUtility.createSessionFactory();
        session = sessionFactory.openSession();
        System.out.println("key in like dao" + questionId);
        QuestionEntity qe = (QuestionEntity) session.get(
                QuestionEntity.class, questionId);
        if (qe != null) {
            // session.getTransaction().begin();
            updatedDownvote = qe.getDownvotes() + 1;
            System.out.println(updatedDownvote);
            qe.setUpvotes(updatedDownvote);
            session.saveOrUpdate(qe);

        }
    } catch (HibernateException exception) {
        throw new Exception("DAO.TECHNICAL_ERROR");
    } catch (Exception exception) {
        throw exception;
    } finally {
        if (session.isOpen() || session != null) {
            session.close();
        }
    }
    return updatedDownvote;
}

public String user(Integer question) throws Exception {
    // List<String> quesString =null;
    // String us="";
    String userFound = null;
    SessionFactory sessionFactory = null;
    Session session = null;

    try {
        System.out.println("dao tag k try me");
        // quesString=new ArrayList<String>();
        sessionFactory = HibernateUtility.createSessionFactory();
        session = sessionFactory.openSession();
        QuestionEntity tag = new QuestionEntity();

        System.out.println("dao" + question);

        // session.persist(ques);

        // session.getTransaction().begin();

        // Query query2 =
        // session.createQuery("select qe.userId from QuestionEntity qe where questionId=?");
        // query2.setString(0, question);
        QuestionEntity qe = (QuestionEntity) session.get(
                QuestionEntity.class, question);
        userFound = qe.getUserId();
        System.out.println(userFound);
        /*
         * for(QuestionEntity tagEntity:tagList){
         * System.out.println("UserID=>"+tagEntity.getUserId());
         * us=tagEntity.getUserId();
         * 
         * }
         */

    } catch (HibernateException exception) {
        exception.printStackTrace();
        DOMConfigurator.configure("src/com/infy/resources/log4j.xml");
        Logger logger = Logger.getLogger(this.getClass());
        logger.error(exception.getMessage(), exception);
        throw new Exception("DAO.TECHNICAL_ERROR");
    } catch (Exception exception) {
        exception.printStackTrace();
        DOMConfigurator.configure("src/com/infy/resources/log4j.xml");
        Logger logger = Logger.getLogger(this.getClass());
        logger.error(exception.getMessage(), exception);
        throw exception;
    } finally {
        if (session.isOpen() || session != null) {
            session.close();
        }
    }
    return userFound;
}

}

1 个答案:

答案 0 :(得分:0)

正在发生的事情是您的Oracle数据库配置为支持&#34; x&#34;每个用户的并发会话数。 因此,你正在绊倒这个问题。 您需要与管理数据库的人员合作,以增加每次使用的并发会话。

请参阅:Getting ORA-02391: SESSIONS_PER_USER limit