Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
What happens in a SQL database when we use nested JoinColumn in entity

I am going through some code and it uses nested @JoinColumn for one of the associations, as following:

@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumns({@JoinColumn(name = "QuestId"), @JoinColumn(name = "GuildId")})
private GuildQuests guildQuest;

I understand that when I do something like the following:

@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumns(name="GuildQuestId")
private GuildQuests guildQuest;

I am creating a column with the name GuildQuestId in the table and it has a foreign key constraint with the entity GuildQuests.

However, what will the nested @JoinColumn(first code snippet) do?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Your first snippet is saying that you specify multiple foreign keys for the same association.

Example:

@ManyToOne
@JoinColumns({
    @JoinColumn(name="ADDR_ID", referencedColumnName="ID"),
    @JoinColumn(name="ADDR_ZIP", referencedColumnName="ZIP")
})
public Address getAddress() { return address; }

Edit: You're actually not creating any foreign keys with (both example) in the database. If you use for example Hibernate, Hibernate does not create any foreign keys on database level itself.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!