I’ve a legacy code that create 2 SessionFactory for the same database (for some unkown reason)
and it works , thatis 2 session factories are created in version 3.x
all entites are in hbm format for now
when I use the same code in version 5.4.x I get the following excption:
org.hibernate.DuplicateMappingException: Duplicate query mapping NAMES_QUERY_NAME
can some explain me why I get this error since I have only ine named query with that name or what have changed in version 5.X? Moreover when I use JPA annotation instead of hbm I don’t get this error.
And is there any reason to use 2 session factories for the same DB (one DB in system)
Maybe you include the same file multiple times? One possible reason for using multiple session factories is when you want to use a different data source for the second session factory. One could use a data source with read committed isolation level and the other serializable. Or one could be connecting to the primary whereas the other connects to a read-only secondary database.
I figured it out. I have only one hbm file. The thing is I use the same Configuration objet for both SessionFactories and from debugging I see the same instance StandardServiceRegistry is accesed with calling buildSessionFactory() method.
To solve it I cearted 2 different instanes of Configuration class and called on each of them buildSessionFactory();