java - Hibernate with more than one dataBase -
i need use hibernate 2 or more bases. since these bases have same table, imagine there no problem when using same objects paras tables repeat. being, wonder how spend other files on hibernateutil establishing connection, using different files hibernate.cfg.xml, same mapping properties.
i imagine it's along these lines:
sessionfactory = new annotationconfiguration().configure().buildsessionfactory();
but dont have idea how configure other file.
the thing have 2 different session factory providers, each 1 configured corresponding data base.
in example below hibernateutildb1
use configuration in hibernate-db1.cfg.xml
, , hibernateutildb2
use hibernate-db2.cfg.xml
.
public class hibernateutildb1 { private static final sessionfactory sessionfactory = buildsessionfactory(); private static sessionfactory buildsessionfactory() { try { return new configuration().configure("hibernate-db1.cfg.xml").buildsessionfactory(); } catch (throwable ex) { ...} } ...
and:
public class hibernateutildb2 { private static final sessionfactory sessionfactory = buildsessionfactory(); private static sessionfactory buildsessionfactory() { try { return new configuration().configure("hibernate-db2.cfg.xml").buildsessionfactory(); } catch (throwable ex) { ...} } ...
Comments
Post a Comment