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 3357028
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:35:05+00:00 2026-05-18T02:35:05+00:00

I have two classes Foo and Bar mapped to two different tables, and I’d

  • 0

I have two classes Foo and Bar mapped to two different tables, and I’d like them to use the JOINED inheritance strategy, but joined using two non-keyed columns. The schema is pretty weird, but I’m stuck with it. Here’s my setup:

@Entity
@Table(name="foo")
@Inheritance(strategy=InheritanceType.JOINED)
public class Foo {
    @Id
    private Integer uniqueFooId;

    @Column(name="column1")
    private String column1;

    @Column(name="column2")
    private String column2;

    @Column(name="someValue")
    private String someValue;
}

@Entity
@Table(name="bar")
public class Bar extends Foo {
    @Id
    private Integer uniqueBarId;

    @Column(name="column1")
    private String column1;

    @Column(name="column2")
    private String column2;

    @Column(name="someOtherValue")
    private String someOtherValue;
}

I’m not sure how @Inheritance decides what column to use to join against, but I’m assuming by default it uses the primary key(s). I’d like to join them against not just one column other than the primary key but two, in this case column1 and column2.

I might even be going about this the wrong way. I’d appreciate any help or suggestions. Thanks!

  • 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-05-18T02:35:05+00:00Added an answer on May 18, 2026 at 2:35 am

    JPA only allows multiple tables or inherited tables to be joined by the Id columns. What JPA provider are you using? Some provide other options.

    See,
    http://en.wikibooks.org/wiki/Java_Persistence/Tables#Multiple_tables_with_foreign_keys

    If using EclipseLink you can define any type of join you desire using a DescriptorCustomizer and addForeignKeyFieldNameForMultipleTable().

    Otherwise, if you can’t change the schema, you could try creating a view that does the join, and use TABLE_PER_CLASS inheritance and map the subclass to the view.

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

Sidebar

Related Questions

I have two classes, Foo and Bar, that have constructors like this: class Foo
Let's say we have two classes, Foo and Foo Sub, each in a different
Let's say I have two classes Foo and Bar, and I want to make
I have two classes: class Foo { public Bar SomeBar { get; set; }
I have two classes, Foo<T> and Bar<T> , derived from Base . Each overrides
Suppose I have two classes with the same interface: interface ISomeInterface { int foo{get;
I have two classes A and B in two different .NET assemblies: AssemblyA and
I have two classes declared like this: class Object1 { protected ulong guid; protected
I have two classes that depend on each other: class Foo; //forward declaration template
I have two classes, and want to include a static instance of one class

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.