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

  • Home
  • SEARCH
  • 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 8963813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:26:29+00:00 2026-06-15T16:26:29+00:00

I have two tables that I would like to treat as a single model

  • 0

I have two tables that I would like to treat as a single model class in Hibernate/Spring, however their only relationship can be established through a third table. For example…

tableA {  
   id integer <PK>
   username varchar2(25 byte)
}
tableB {
   personID varchar2(15 byte) <PK>
   divisionID integer
   positionID integer
}
tableC {
   personID varchar2(10) <FK>
   username varchar2(25 byte)
}

While it would be very nice to simply add the personID as a column in tableA, circumstances do not permit. I would, however, like to interact with these tables using one model in hibernate, such as the one below…

@Entity
@Table(name="tableA")
public class myTable {
   @Id
   @GeneratedValue
   private int id;
   private String username;
   @Formula("(select distinct tableC.personID from tableC where upper(tableC.username) = upper(THIS_.username) and tableC.personID is not null)")
   String personID;
   @Formula("(select distinct tableB.divisionID from tableB where tableB.personID = THIS_.personID)")
   int divisionID;
   @Formula("(select distinct tableB.oositionID from tableB where tableB.personID = THIS_.personID)")
   int positionID;

   //getters, setters, etc...
}

I know that the way I have it written here is impossible, I’m just trying to convey the idea. When I go to save or update the database later on, I would like for Hibernate to be able to update the appropriate tables from which each attribute came.

I have explored using @Transient, @SecondaryTables, and a few others but I haven’t found a good way to make this work. Is it possible to do this the way that I want to? If so, what approach/annotations should I use? If not, what alternative approach should I take? I am relatively new to Hibernate and Spring, so please bear with me.

  • 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-15T16:26:30+00:00Added an answer on June 15, 2026 at 4:26 pm

    I’m sure there’s a way to do this; I don’t have an answer for you.

    But your question suggests to me that you’re not thinking properly about Hibernate. It’s an ORM tool – Object-Relational Mapping. If you’re still thinking just in terms of tables and SQL, loading values into primitives, then Hibernate isn’t the right tool.

    I’d suggest just using Spring SimpleJdbcTemplate rather than Hibernate if you don’t have objects to map your data into.

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

Sidebar

Related Questions

I have two tables that I would like to display as a single result,
I have two tables that are considered a single entity in my domain model.
I have two great tables that I would like to use as foundation for
I have two MySQL tables (product and price history) that I would like to
I have two tables that I would like to compare for duplicates. These tables
I have two tables that I would like to join with the following columns:
I have two tables that I would like to get data and from by
I have two tables customer and activation that I would like to join. Here
I have two tables in MySQL that are related. I would like to find
I was thinking that I would have two tables for mysql. One for storing

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.