How to Update an Entity from a Thread in Dropwizard, Hibernate

耗尽温柔 提交于 2019-12-19 11:28:06

问题


I have a thread that waits until a process is complete and then needs to update an entity. But I get

Exception in thread "Thread-22" org.hibernate.HibernateException: No session currently bound to execution context

I have tried opening a new session (see the code below). Session management is normally handled by @UnitOfWork, but this annotation seems to apply only to resources.

public class ConfigDAO extends AbstractDAO<Config>
{
    private final SessionFactory sessionFactory;

    public ConfigDAO(SessionFactory factory) {
        super(factory);
        this.sessionFactory = factory;
    }

    public Config updateFromNewSession(Config config) {
        System.out.print("current session: ");
        Session session = sessionFactory.openSession();
        System.out.println(session);
        session.persist(config);
        session.close();
        return config;
    }

来源:https://stackoverflow.com/questions/55548726/how-to-update-an-entity-from-a-thread-in-dropwizard-hibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!