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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:49:39+00:00 2026-05-13T01:49:39+00:00

I wonder how JPA defines to handle following scenario: Table A: | Table B:

  • 0

I wonder how JPA defines to handle following scenario:

Table A: | Table B:
ID  FK_B | ID
1   10   | 10
2   null | 12
3   11   |

I want all Table A entries with FK_B NULL or referencing not available Table B entry.

public class A implements Serializable {
    @Id
    private Long id;

    @JoinColumn(name = "FK_B", nullable = true)
    @ManyToOne
    private B b;
}

public class B implements Serializable {

    @Id
    private Long id;
}

Is it defined, what happens if I use

SELECT a FROM A a LEFT JOIN a.b WHERE a.b IS NULL

or: (Is this possible?)

SELECT a FROM A a LEFT JOIN B b on (b = a.b) WHERE b IS NULL

What I need is a list containing

A(id = 2)
A(id = 3)

Thanks a lot!

  • 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-13T01:49:39+00:00Added an answer on May 13, 2026 at 1:49 am

    Row #3 in your Table A is illegal by definition; if there’s no B with ID=11 you can’t have that row in table A for you’d be violating the foreign key constraint.

    As far as getting all rows from A where B is null, your first query should work. You can also try:

    SELECT a FROM A a WHERE a.b.id IS NULL
    

    although I’m not 100% sure whether that’s valid JPA QL syntax (it works for Hibernate)

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

Sidebar

Related Questions

wonder what's wrong <table id=tblDomainVersion> <tr> <td>Version</td> <td>No of sites</td> </tr> <tr> <td class=clsversion>1.25</td>
wonder whether someone can help me with the following one... I have a struct
I wonder, using Eclipse's PyDev plugin , how come documentation does not always show
I wonder not only what is Facet but also what is Facet 'in physical
i wonder what are the pitfalls of not adapting it, as i am facing
It's possible to define enumerations in JPA using either @Enumerated(EnumType.ORDINAL) or @Enumerated(EnumType.STRING) I wonder
I wonder why I get QuerySyntaxException: [Entity] is not mapped , although Hibernate is
With JPA, we can use manually OPTIMISTIC or PESSIMISTIC locking to handle entity changes
I wonder if someone can help, I want to run a schedule task and
I have an application that uses a Spring-EntityManager (JPA) and I wonder what happens

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.