从Configuration入手。在hibernate.cfg.xml中配置2个数据源后,当创建Configuration时针对2个数据源创建2个Configuration实例。之后,就是一般的orm操作。从一个源里实例化出来,在持久化到另一个源里。

解决方案 »

  1.   

    使用2个以上的数据源的基本上就是分布式应用,该用EJB。
      

  2.   

    我在用buildSessionFactory()创建SessionFactory时,如果创建两个,如下所示:
    File file1 = new File("D:\\src\\gateway.cfg.xml");
    Configuration cfg1 = new Configuration().configure(file1);
    SessionFactory sessions1 = cfg1.buildSessionFactory();File file2 = new File("D:\\src\\hibernate.cfg.xml");
    Configuration cfg2 = new Configuration().configure(file2);
    SessionFactory sessions2 = cfg2.buildSessionFactory();就会出现缓存管理错误。如下所示:
    Exception in thread "main" org.hibernate.cache.CacheException: Attempt to restart an already started EhCacheProvider. Use sessionFactory.close()  between repeated calls to buildSessionFactory. Consider using net.sf.ehcache.hibernate.SingletonEhCacheProvider. Error from  ehcache was: Cannot parseConfiguration CacheManager. Attempt to create a new instance of CacheManager using the diskStorePath "D:\\projects\\java\\circadian\\WebRoot\\WEB-INF\\temp" which is already used by an existing CacheManager. The source of the configuration was classpath.应该如何解决?
      

  3.   

    我也是创建两个Configuration,也创建两个SessionFactory,可是事实就是行不通。
      

  4.   

    现在发现问题了,
    是hibernate-3.2.0.CR2.zip这个版本有问题.
    换一个版本如:hibernate-3.2.0.CR5.zip就好了.
      

  5.   

    是你的缓存文件冲突EhCacheProvider   把你的缓存关了,或者改成内存方式的缓存
      

  6.   

    以上的错误,是因为使用的hibernate包有问题造成的。可以换一个包来试用。
    MyEclipse所带的一些开发包,问题多多。