0

I have two databases (Oracle and SqlServer) and I have the same table (Province) in both. I'm using JPA with Hibernate and need to perform operations to any of those databases.

I have an hbm mapping file for each table but both refer to the same class (Province.java). I've configured hibernate.Oracle.cfg.xml and hibernate.SqlServer.cfg.xml in order to declare the mappings appropriately for each DB.

I'm also using Spring.

Here's my problem. When the application loads (actually JUnit) it tries to load both hbm files throwing DuplicateMappingException because Province.java is twice. Moreover, if I only keep one hbm file and one hibernate config file it still throws DuplicateMappingException; BUT if I remove the mapping from the hibernate config file then it works (but I don't want this). This means that the hbm file is automatically loaded and it is then loaded again due to it is declared in the config file.

Is there a way I can avoid hbm files to be automatically loaded?

j0k
  • 22,600
  • 28
  • 79
  • 90

1 Answers1

0

I was finally able to find the solution to this problem.
I added <exclude-unlisted-classes>false</exclude-unlisted-classes> to both persistence units in persistence.xml file and it prevented the hbm files to be loaded automatically. I also had to place the mapping in both hibernate.Oracle.cfg.xml and hibernate.SqlServer.cfg.xml.