写2个hibernate.cfg.xml,开2个SessionFactory

解决方案 »

  1.   

    不需要改名字?都是hibernate.cfg.xml,不用1,2分开?写在一个文件夹下?
    稍微详细点,好吗?
    据个例子,我不是很明白
      

  2.   

    需要自己绑定config文件,同样的名字方在一个文件夹下面是不能的,呵呵。
      

  3.   

    public class HibernateUtil {    private static final SessionFactory sessionFactory1;
        private static final SessionFactory sessionFactory2;
        static {
            try {
                // Create the SessionFactory from hibernate.cfg.xml
                sessionFactory1 = new Configuration().configure("hibernate1.cfg.xml").buildSessionFactory();
                sessionFactory2 = new Configuration().configure("hibernate2.cfg.xml").buildSessionFactory();        } catch (Throwable ex) {
                // Make sure you log the exception, as it might be swallowed
                System.err.println("Initial SessionFactory creation failed." + ex);
                throw new ExceptionInInitializerError(ex);
            }
        }    public static SessionFactory getSessionFactory1() {
            return sessionFactory1;
        }
        public static SessionFactory getSessionFactory2() {
            return sessionFactory2;
        }
    }
      

  4.   

    谢谢三生,可是当我使用默认时,能找到hibernate.cfg.xml
    但我在config("hibernate.cfg.xml")后不能找到此文件,我将hibernate.cfg.xml文件放进java source中,这是为何??
      

  5.   

    sandy_daydream(sandy) ( ) 信誉:100  2006-03-29 11:06:00  得分: 0  
     
     
       谢谢三生,可是当我使用默认时,能找到hibernate.cfg.xml
    但我在config("hibernate.cfg.xml")后不能找到此文件,我将hibernate.cfg.xml文件放进java source中,这是为何??  
     
    -------------------
    先用绝对路径试,把问题确定下来!
      

  6.   

    讨论这类问题的加我QQ啊,我们一起讨论,我QQ71179638 注明hibernate