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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:44:04+00:00 2026-05-14T21:44:04+00:00

Currently I have two tables in my database Encounters and Referrals : There is

  • 0

Currently I have two tables in my database Encounters and Referrals:

There is a one to many relationship between these two tables. Currently they are linked together with foreign keys. Right now I have

    public class Encounter extends JPASupport implements java.io.Serializable { 
        @Column(name="referralid", unique=false, nullable=true, insertable=true, updatable=true)
           public Integer referralid; 
}

But what I really want is

     public class Encounter extends JPASupport implements java.io.Serializable { 
..........
        @OneToMany(cascade=CascadeType.PERSIST)
        public Set<Referrals> referral;
............
    }

So that I can eventually do a query like this:

   List<Encounter> cases = Encounter.find(
               "select distinct p from Encounter p join p.referrals as t where t.caseid =103"
).fetch();

How do I tell JPA that even though I have non-standard column names for my foreign keys and primary keys that its the object models that I want linked, not simply the integer value for the keys?

Does this make sense?

  • 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-14T21:44:04+00:00Added an answer on May 14, 2026 at 9:44 pm

    I can’t tell from your example, does a referral have many encounters on it, or does an encounter have many referrals on it? You seem to go back and forth. This would be for each Referral has lots of Encounters:

    public class Encounter extends JPASupport implements java.io.Serializable {    
          @ManyToOne
          @JoinColumn(name="referralid", referencedColumnName="id",//otherstuff)
          private Referral referral; 
    }
    
    
     public class Referral extends JPASupport implements java.io.Serializable { 
    
        @OneToMany(cascade=CascadeType.PERSIST, mappedBy="referral")
        private Set<Encounter> encounters;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have two joined tables in a SQL Server database, one with news
I currently have a database with two tables in it one hold lets say
The database I am working with currently does have two tables, one holding the
Excuse the long question! We have two database tables, e.g. Car and Wheel. They
I currently have a database with two tables called Articles and Tags . In
Brief: I'm fairly new to databases and currently have one with two tables for
How can one optimize the database structure that currently has two tables tbl_incoming and
So essentially I have two tables, containing URLS and TAGS, with a has-and-belongs-to-many relationship
I'm currently facing a database query issue. I have two tables, items and details
I have a simple database with two tables: Photo and Tag . There is

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.