[英]Is it possible to save object in two different schemas using single hibernate session?
I am trying to persist person object into two different schemas using single hibernate session as follows 我试图使用单个hibernate会话将person对象持久化为两个不同的模式,如下所示
I have Person Class having certain fields in it 我有Person Class,里面有某些字段
@Entity
public class Person {
@Id
@GeneratedValue
private Integer id;
@Column(name="firstname")
private String firstName;
@Column(name="lastname")
private String lastName;
@Column(name="age")
private int age;
//getters and setters methods
Now I need to save the object into two different schemas using single hibernate session. 现在我需要使用单个hibernate会话将对象保存到两个不同的模式中。 Can this happens, can anybody have any idea please help me. 这可能发生,任何人都有任何想法请帮助我。
I have answered my question 我已经回答了我的问题
Its not possible using same session for persist objects into two different schemas. 它不可能将持久化对象的相同会话用于两个不同的模式。
I have done like below: 我做了如下:
I have create two hibernate configuration files for the two different schemas you need to persist the object. 我为持久化对象所需的两个不同模式创建了两个hibernate配置文件。
Here is the code snippet: 这是代码片段:
Configuration config1 = new Configuration().configure(configfile1);
Configuration config2 = new Configuration().configure(configfile2);
I have opened the sessionfactory's by using both configuration instances 我已经使用两个配置实例打开了sessionfactory
SessionFactory sessionFactory1 = config1.buildSessionFactory();
SessionFactory sessionFactory2 = config2.buildSessionFactory();
I have opened two new sessions from sessionFactory instances 我从sessionFactory实例中打开了两个新会话
Session session1 = sessionFactory1.openSession();
Session session2 = sessionFactory2.openSession();
Now I have persisted the objects to two different schemas. 现在我将对象持久化为两个不同的模式。
But Not sure whether this is correct way to handle. 但不确定这是否是正确的处理方式。
Thanks 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.