Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9230421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:49:17+00:00 2026-06-18T05:49:17+00:00

I’m using DB2 on AS400 (iSeries), hibernate 3, spring 2.0 and Java 6 and

  • 0

I’m using DB2 on AS400 (iSeries), hibernate 3, spring 2.0 and Java 6 and I have two tables (physical files) on two different libraries like this: Library1/TableA and Library2/Table2, so normally I need to a sessionFactory for each library like this:

<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’m trying to join the tables on my class like this:

@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 sessionFactory at a time and my TableADao loads the sessionFactory1AS400 which has no knowledge of the existence of the TableB.
To overcome that problem I moved 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 the definition of the schema on class TableB:

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

This time my test ran OK and gave me the correct query:

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

Now my problem is that the schema definition on TableB is hardcoded instead of being loaded from a configuration file which is the perfect scenario, since we have different environments where the libraries names are different.

Is there a way to have the schema definition on TableB come from a configuration on spring or any other way to join these tables?

Thanks in advance for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:49:18+00:00Added an answer on June 18, 2026 at 5:49 am

    Joining tables over 2 different libraries is dead easy, all you need are some extra JDBC parameters:

    In the JDBC url add parameter “libraries” and “naming”. E.g.
    jdbc:as400://systemName/;libraries=”Library1 Library2″;naming=system

    With the above JDBC url you will be able to perform this query:

    select * from TableA
    inner join TableB on … = …

    The iSeries machine will use the “libraries” parameter to find the physical files. Make you your physical file names are unique across both libraries to prevent conflicts.

    Cheers,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using DB2 database and hibernate framework. There are two tables such as
i have problem using LIKE structure in DB2 : for example: select * from
The database I'm accessing has two tables I need to query using DB2 SQL,
I have two tables in two different databases with same structure. I am exporting
I am using db2 and I want to find tables, having a column named
Ok So I have an AS400/iSeries running v5r4. I have an application that was
Hibernate criteria, using DB2 dialect, generates the following SQL with composite keys in the
I'm using DB2 9.5. Is there exists tool like SQL Server Profiler? I want
I am using DB2 and have the following table (Table A - 3 Columns)
I am using DB2 9.7 enterprise edition on Windows 7. I have created a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.