Yes, this is the way you build up entity manager factory but you found for task server and what you are looking for (as original post refers to) is session state persistence.
So you should look for a place in your application where you create stateful sessions rather than knowledge base. There you should utilize JPAKnowledgeService to create session where one of the arguments for the newStatefulKnowledgeSession method is environment that should contain entity manager factory instance.
HTH