.cfg.xml
文件中配置了两个数据库现在DB1中的一些表是链接到 DB2 中的表,例如DB1.Branch.Branchid
是主键,引用DB2.OfficeAddress.Branchidf
的前导键在HQL查询中我想使用以下内容访问DB1.Branch
的详细信息DB@.Lesseemaster.Branchid
执行查询哪个数据库sessionfactory需要使用?完全混淆我没有得到任何参考,我们可以映射位于Hibernate不同数据库中的相关表中的数据。hibernate.cgf.xml
<hibernate-configuration>
<session-factory >
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.url">jdbc:mysql://localhost:3306/vrfdb</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="current_session_context_class">thread</property>
<mapping class="LA_DAO.OwnerDAO"/>
<mapping class="LA_DAO.PropertyDAO"/>
<mapping class="LA_DAO.ActivityDAO"/>
<mapping class="LA_DAO.LesseeDAO"/>
</session-factory>
</hibernate-configuration>
&LT;&LT; hibernate1.cgf.xml&GT;&GT;
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.url">jdbc:mysql://localhost:3306 /leavemanagement</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="current_session_context_class">thread</property>
<mapping class="LA_DAO.BranchDAO"/>
</session-factory>
</hibernate-configuration>
package LA_DAO;
@Entity
@Table(name = "branchmaster" )
public class BranchDAO {
@Id
@GeneratedValue
@Column(name = "branch_id")
private int id;
@Column(name = "branch_type_code")
private int br_main_id;
@Column(name = "branch_name")
private String branchName;
@Column(name = "branch_code")
private String branchCode;
//getters n setters
}
&LT;&GT; 包LA_DAO;
@Entity
@Table(name = "lessee_master")
public class LesseeDAO {
@Id
@GeneratedValue
@Column(name = "id")
private int lesseeId;
@Column(name = "Name")
private String LesseeName;
@Column(name ="Address")
private String LesseeAddress;
@Column(name = "ContactNumber")
private String LesseeNumber;
@Column(name ="EmailID" )
private String LesseeEmail;
@OneToOne(fetch = FetchType.EAGER )
@JoinColumn(name = "BranchId")
private BranchDAO branch;
}