f_si2008 2015-06-17 02:21 采纳率: 0%
浏览 1820

Transaction Session 问题求助!

HibernateUtil.java
*

  • @author Tyler
    */
    public class HibernateUtil {

    private static final SessionFactory sessionFactory;

    static {
    try {
    // Create the SessionFactory from standard (hibernate.cfg.xml)
    // config file.
    Configuration configuration = new Configuration().configure();

    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()

    .applySettings(configuration.getProperties()).build();

    sessionFactory = configuration

    .buildSessionFactory(serviceRegistry);

    // return sessionFactory;
    } catch (Throwable ex) {
    // Log the exception.
    System.err.println("Initial SessionFactory creation failed." + ex);
    throw new ExceptionInInitializerError(ex);
    }
    }

    public static SessionFactory getSessionFactory() {
    return sessionFactory;
    }

    }

    //查询
    private List criteriaIUL_get(String key) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();
    // Query q = session.createQuery(UI_BaseOnEquipmentId);
    Criteria criteria = session.createCriteria(InfosysUserInfo.class);
    Criterion criterion;
    switch (key.length()) {
    case 5:
    criterion = Restrictions.eq("equipmentId", key);
    break;
    case 11:
    criterion = Restrictions.or(Restrictions.eq("phone1", key), Restrictions.eq("phone2", key));
    break;
    default:
    criterion = null;
    break;
    }
    if (criterion == null) {
    return null;
    }
    criteria.add(criterion);
    List resultList = criteria.list();
    session.getTransaction().commit();
    return resultList;
    }
    -------------------------------------
    hibernate.cfg.xml

thread
第一次事务没有问题,第二次查询时出现:(这是什么问题)
Exception in thread "AWT-EventQueue-0" org.hibernate.TransactionException: nested transactions not supported
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:154)
at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1435)
at sun.reflect.GeneratedMethodAccessor41.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:356)
at com.sun.proxy.$Proxy0.beginTransaction(Unknown Source)
at frame.JFrameMain.criteriaIUL_get(JFrameMain.java:51)
at frame.JFrameMain.jBqueryUserMouseClicked(JFrameMain.java:617)
at frame.JFrameMain.access$12(JFrameMain.java:615)
at frame.JFrameMain$13.mouseClicked(JFrameMain.java:507)
at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

  • 写回答

3条回答 默认 最新

  • f_si2008 2015-06-17 02:42
    关注

    这是没有关闭的原因嘛?

    评论

报告相同问题?

悬赏问题

  • ¥15 luckysheet
  • ¥25 关于##爬虫##的问题,如何解决?:
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题