Hibernate configures two data sources - asked on the 9CBS community

xiaoxiao2021-03-06  89

First, a profile can only correspond to one database, and must have multiple profiles in response to multiple configuration files; configuration files can have two formats in .xml and .properties, but initialization methods are different. Connecting different databases requires initializing different profiles:

CONFIGURATION CONFIG = New Configuration ();

// If you use .xml configuration file config.addfile (". XML file name");

// If you use .properties' configuration file to trouble a little Properties P = New Properties (); p.Load (New BufferedInputStream (New FileInputStream (". Properties file name")); config.addproperties (p);

// The above can only use one

SessionFactory sf = config.configure (). BuildSessionFactory ();

转载请注明原文地址:https://www.9cbs.com/read-96042.html

New Post(0)