Joining two tables from two different libraries using java, DB2, spring and hibernation

I use DB2 on AS400 (iSeries), hibernate 3, spring 2.0 and Java 6, and I have two tables (physical files) in two different libraries, such as: Library1 / TableA and Library2 / Table2, so I usually need for sessionFactory for each library, for example:

<bean id="sessionFactory1AS400"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSourceAS400" />
        <property name="annotatedClasses">
            <list>
                <value>com.appllication.model.TableA</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props><prop key="hibernate.default_schema">Library1</prop>
            </props>
        </property>
    </bean>

and

<bean id="sessionFactory2AS400"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSourceAS400" />
        <property name="annotatedClasses">
            <list>
                <value>com.appllication.model.TableB</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props><prop key="hibernate.default_schema">Library2</prop>
            </props>
        </property>
    </bean>

I am trying to join tables in my class as follows:

@Entity(name = "TableA")
public class TableA {

@ManyToOne(targetEntity=TableB.class, fetch=FetchType.LAZY)
    @JoinColumns(
            {
                @JoinColumn(name="column1", referencedColumnName="column1", insertable=false, updatable=false),
                @JoinColumn(name="column2", referencedColumnName="column2", insertable=false, updatable=false)
            })
    private TableB tableB;

}

But when I run my unit test, it fails because the DAO class can only load one session at a time, and my TableADao loads sessionFactory1AS400, which does not know about the existence of TableB. To overcome this problem, I switched my TableB to the same sessionFactory as TableA:

<bean id="sessionFactory1AS400"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSourceAS400" />
        <property name="annotatedClasses">
            <list>
                <value>com.appllication.model.TableA</value>
<value>com.appllication.model.TableB</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props><prop key="hibernate.default_schema">Library1</prop>
            </props>
        </property>
    </bean>

And added a schema definition in the TableB class:

@Entity(name="TableB")
@Table(schema="Library2")
public class TableB implements Serializable {
}

:

SELECT * FROM Library1.TableA ta INNER JOIN Library2.TableB tb ON ta.column1 = tb.column1 AND ta.column2 = tb.column2

, TableB , , , .

, TableB spring ?

.

+3
2

, , , JDBC:

URL- JDBC "" "". . jdbc: as400://systemName/; libraries = "Library1 Library2"; naming = system

URL- JDBC :

* A TableB on... =...

iSeries "libraries" . , .

,

+2

Hibernate *.hbm.xml config ?

<class name="TableB" table="table_b" schema="Library2">
    . . .
</class>

*.hbm.xml XML- Spring, , PropertyPlaceHolderConfigurer .

+1

All Articles