无法更新testUpdateBookOrdersShippingAddress

时间:2019-05-23 11:39:26

标签: oracle hibernate connection-pooling

我在更新BookOrder时遇到问题。根据多对多关系,BookOrder通过组合键连接到DetailOrder。

错误如下所示。

May 23, 2019 2:33:48 PM com.mchange.v2.c3p0.impl.NewPooledConnection 
INFO: [c3p0] Exceptions occurred while trying to close a PooledConnection's resources normally.
May 23, 2019 2:33:48 PM com.mchange.v2.c3p0.impl.NewPooledConnection 
INFO: [c3p0] NewPooledConnection close Exception.
java.sql.SQLException: ORA-03106: fatal two-task communication protocol error

    at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:494)
    at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:441)
    at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:436)
    at oracle.jdbc.driver.T4C7Ocommoncall.processError(T4C7Ocommoncall.java:86)
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:623)
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:252)
    at oracle.jdbc.driver.T4C7Ocommoncall.doOLOGOFF(T4C7Ocommoncall.java:62)
    at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:908)
    at oracle.jdbc.driver.PhysicalConnection.close(PhysicalConnection.java:2005)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:642)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.closeMaybeCheckedOut(NewPooledConnection.java:255)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:622)
    at com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:1076)
    at com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:1101)
    at com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:1062)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$100(BasicResourcePool.java:44)
    at com.mchange.v2.resourcepool.BasicResourcePool$5.run(BasicResourcePool.java:1316)

May 23, 2019 2:33:48 PM com.mchange.v2.resourcepool.BasicResourcePool 
WARNING: Failed to destroy resource: com.mchange.v2.c3p0.impl.NewPooledConnection@3dd18dc6
java.sql.SQLException: Some resources failed to close properly while closing com.mchange.v2.c3p0.impl.NewPooledConnection@3dd18dc6
    at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:664)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.closeMaybeCheckedOut(NewPooledConnection.java:255)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:622)
    at com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:1076)
    at com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:1101)
    at com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:1062)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$100(BasicResourcePool.java:44)
    at com.mchange.v2.resourcepool.BasicResourcePool$5.run(BasicResourcePool.java:1316)

我认为可能存在会话问题。会话可以在需要打开时自动关闭。

我的考试班

@Test
    public void testUpdateBookOrdersShippingAddress() {
        Integer orderId = 48;
        BookOrders bookorders = ordersDAO.get(orderId);

        System.out.println("Update Before (ShippingAddress) : " + bookorders.getShippingAddress());

        bookorders.setShippingAddress("New Home Shipping Address");

        try {
            ordersDAO.update(bookorders);
        } catch (Exception e) {
            e.printStackTrace();
        }


        BookOrders updatedOrder = ordersDAO.get(orderId);

        System.out.println("Update After (ShippingAddress) : " + updatedOrder.getShippingAddress() );

        assertEquals(bookorders.getShippingAddress(), updatedOrder.getShippingAddress());

    }

获取和更新方法的休眠类。

public T update(T t) {

        Session session = sessionFactory.openSession();
        Transaction transaction = null;
        try {
            transaction = session.beginTransaction();

            session.merge(t);
            session.flush();
            session.getTransaction().commit();
            session.close();

        }catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
            transaction.rollback();
        }

        return t; 
    }

    public T get(Class<T> type,Object id) {

        Session session = sessionFactory.openSession();
        Transaction transaction = null;
        T t = null;
        try {
            transaction = session.beginTransaction();

            t = session.get(type, (int)id);
            session.flush();
            session.getTransaction().commit();
            session.close();

        }catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
            transaction.rollback();
        }

        return t; 
    }

1 个答案:

答案 0 :(得分:0)

在基于通用类型的休眠类的更新功能中,我可以使用session.update(t);代替session.merge(t); and I could solve it.