0
두 개의 서로 다른 데이터베이스에 대해 두 개의 다른 설정 파일을 가지고 있으며 각각의 세션은 세션이 열려있을 때마다 가지고있다. 아래는 코드입니다. Hibernate와 두개의 다른 데이터베이스를 연결할 수 없다.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">url</property>
<property name="hibernate.connection.username">userName</property>
<property name="hibernate.connection.password">password</property>
<mapping class="com.tableClassName" />
</session-factory>
</hibernate-configuration>
Second.cfg.xml
내 모든 자격 증명을 제거하고 더미 하나
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="connection.url">URL</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.username">userName</property>
<property name="connection.password">Password</property>
<mapping class="com.ClassNameOfTheTable" />
</session-factory>
</hibernate-configuration>
one.cfg.xml 내 설정 파일
을에 배치 한 보안상의 이유로 - 참고
HibernateStratApp 클래스 (여기서 내가 설정된 파일을 설정)
package com.tn.gov;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class HibernateStartApp {
private static final SessionFactory sessionFactory = buildSessionFactory1();
private static final SessionFactory sessionFactory1 = buildSessionFactory2();
Session session=null;
Transaction transaction = null;
private static SessionFactory buildSessionFactory1() {
try {
// Create the SessionFactory from hibernate.cfg.xml
return new Configuration().configure("one.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 getSessionFactoryOne() {
return sessionFactory;
}
public static SessionFactory getSessionFactoryTwo(){
return sessionFactory1;
}
private static SessionFactory buildSessionFactory2() {
try {
// Create the SessionFactory from hibernate.cfg.xml
return new Configuration().configure("two.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);
}
}
}
세션을 열거 나 닫음으로써 값을 검색하고 있습니다.
하지만 내가 failed.org.hibernate.exception.JDBCConnectionException geting 오전 : 드라이버를 호출하는 중 오류 # 연결하려고 할 때 연결하십시오.
하나의 구성에 속성 이름에 "hibernate"접두사가 포함되어있는 것은 맞습니까? 귀하의 코드에는 오류가 포함 된 것으로 보입니다. – svaor