把实体从一个数据库复制到另一个数据库

方法1:
写代码从sessionFactory1中取实体,然后在sessionFactory2中保存实体

方法2:
Session session1 = sessionFacory1.openSession();
Transaction tx1 = session1.beginTransaction();
Customer customer = (Customer)session1.get(Customer.class, 1L));
tx1.commit();
session1.close();

Session session2 = sessionFactory2.openSession();
Transaction tx2 = session2.beginTransaction();
//把Customer对象复制到第二个数据库存储源中
session2.replicate(customer, ReplicationMode.LASTEST_VERSION);
tx2.commit();
session2.close();

你可能感兴趣的:(Hibernate)