Running Query from seperate thread

I have 2 threads. Main thread that has a sessionFactory object and a separate thread that I want to execute a query.

When I write the following (in psedo code):

new Thread( () -> { 
        try(Session s  = sessionFactory.openSession()){
             s.createQuery(SQL COMMAND).executeUpdate();

I see when adding printing that the session is the new thread is open but the executeUpdate never happens.

What is the problem?

What do you mean by “executeUpdate never happens”? How do you know that?

If you are really using a SQL query here, the problem is that you are using the wrong method. You shold use s.createNativeQuery(SQL COMMAND) instead. I guess an exception happens because of that which you are not handling or printing anywhere, hence you don’t see anything happening.