1

I'm using one Session across whole application, but I'm getting error:

Exception in thread "Thread-9" org.hibernate.AssertionFailure: possible non-threadsafe access to the session

This happens accidentally, not always.

In JTable model I have this:

public Object getValueAt(int rowIndex, int columnIndex) {
        Invoice i = invoices.get(rowIndex);
        Object[] values = new Object[] { i.getInvoiceId(), i.getIdent(),
                i.getTotalExclVat(), i.getTotalInclVat(), i.getIssueDate(),
                i.getTaxDate(), i.getDueDate(), i.getPayType(),
                i.getWeight(), i.getSupplier().getName(),
                i.getInvoiceItems().size() };
        return values[columnIndex];
...

Invoice is Hibernate @Entity and @Table and it has InvoiceItems connected to it.

Question is: How should I handle Hibernate Session in Swing JTables to avoid 'possible non-threadsafe access to the session' error?

Thanks.

4

1 回答 1

2

TableModel#getValueAt()正在(或应该)在事件调度线程 (EDT)上运行。正如这里所讨论的,“每个线程/事务都应该从一个SessionFactory. 工厂线程可以TableModel通过invokeLater().

于 2013-05-05T22:52:08.100 回答