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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:14:46+00:00 2026-05-31T04:14:46+00:00

I want to now if can JPQL retrieve the composed object. ObjectA has ObjectB

  • 0

I want to now if can JPQL retrieve the composed object. ObjectA has ObjectB (Aggregation). Can I query ObjectB where there is not link with ObjectA. NAtive Query would be like this:

SELECT * FROM OBJECTB WHERE  ID_OBJECTA = NULL

Sometimes JPA creates an associative entity, but I assumed here just added ID_OBJECTA as the reference to his aggregater.

Thanks for your help.

Class ClassA{
public ClassB b;
}

ClassB{
public String data;

}

I know I can query like this:

Select a from ClassA a join a.b bb//Given a retrieve b

I want to do this:

Select b from ClassB b join ...// ClassB doenst have an a Attribute

How can i query ClassA from ClassB

  • 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-31T04:14:47+00:00Added an answer on May 31, 2026 at 4:14 am

    What you want is a bi-directional One-to-One association. You have two options in this case Lazily or Eagerly loaded. Neither require an explicit join in your JQL unless you want to override lazy loading with eager loading. This is of course predicated on the fact that your annotations/xml defining the relationship between these objects is setup correctly.

    You will need a property in ClassB for type ClassA to persist changes in ClassB’s relationship independent of ClassA. This property will also allow child queries on ClassB to populate the parent ClassA member with data(eager) or query stubs(lazy)

    public ClassA{
       ClassB Child;
    }
    
    public ClassB{
       ClassA parent;
       String data;
    }
    

    Check out this wiki books entry it walks you through setting this up. One To One It oulines a very similiar scenario in dealing with a Person with an Address and laying how to get the person by querying the Address.

    Note: I just read that you are trying to do this without an association. Like other posters have noted its trivial to add this relationship, If its lazy it adds almost no overhead. The only reason I can think of not to do this is some misguided attempt to avoid polluting classB with references to ClassA. Remember “Worse Is Better” Simplicity -> Correctness –> Consistency -> Completeness. Do it the simplest way that solves you’re problem and no simpler.

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

Sidebar

Related Questions

I am new to SharePoint 2010 and I want to now how I can
I want to now if I can use 'scope' as a column name safely
I built an app on cocos2d version 0.8 and now can not find an
I want to replace two things in one select statement. Now I can replace
a few minutes ago I had a discussion with my boss and want now
I deleted a file from a repo and now want to put it back.
I have till now mainly concentrated on web programming thus far and now want
I have a program that is been implemented in C++ which I now want
Let's say I have created two objects from class foo and now want to
i have wrote a script to produce an array of data but now want

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.