hibernatesessionfactory

Two Hibernate SessionFactories creation


I have legacy code that generate 2 SessionFactories for the same database, that is 1 DB and 2 SessionFactories.

When I upgrade to Hibernate 5.4.3 I get

org.hibernate.DuplicateMappingException: Duplicate query mapping

when trying to start up the application. When I create only one Session Factory the above exception does not occur.

Can some explain me the reason and if there is any good reason for 2 session factories for 1 data base?


Solution

  • Seems self-explanatory.. you have tried to map one or more named queries with the same name within the same SessionFactory (SF).

    There are quite a few valid reasons you might want to use multipleSessionFactories.

    Hard to tell without more details. And your best source of "why" is going to be the legacy developer