Multithreaded situation produces UnknownEntityTypeException: Unable to locate persister

Viewed 40

I see other articles talking about this error, but none I saw were quite on point. My situation is that I have an existing quartz task that processes records on a scheduled basis. Written in spring and hibernate and works great. New requirement, we're about to get a DELUGE of high volume that this process can't handle as written. So in addition to some other optimizations, I'm trying to multithread it.

I declared and am using Spring's TaskExecutor, and it definitely invokes the new thread, but as soon as I run a query I get this:

org.hibernate.UnknownEntityTypeException: Unable to locate persister: 119129
at org.hibernate.metamodel.internal.MetamodelImpl.locateEntityPersister(MetamodelImpl.java:647) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]
at org.hibernate.internal.SessionImpl.locateEntityPersister(SessionImpl.java:2951) ~[hibernate-core-5.2.16.Final.jar:5.2.16.Final]

My declaration of the TaskExecutor (which is not null, so it's being created and injected):

<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"></bean>

Where I launch the threads:

    ProcessQueueWorkerThread worker = new ProcessQueueWorkerThread(this);
    taskExecutor.execute(worker);
    workers.add(worker);
          

And the thread itself and the hibernate are pretty uninteresting. The query itself is a simple session.get(id, class); And it's a class that WAS recognized in the main thread. Do I need to do something else to prime this thread? I'm assuming I missed a step, but I did what the example I was following did.

1 Answers

Okay, so it turned out that this had NOTHING to do with threading or spring. Just a REALLY, EPICALLY unhelpful and misleading exception. The problem was that in the reorg to a multithreaded structure I was passing a string into the session.get() for an integer key column. That's all it was. I feel bad for blowing so much time on such a simple thing, but a half-decent error would have saved me hours of time.

Related