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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:24:43+00:00 2026-06-18T06:24:43+00:00

How to join with extra ON clause parameters? I have an SQL: select *

  • 0

How to join with extra ON clause parameters?
I have an SQL:

select * from Address address left outer join  AddressLine line 
              on line.id = address.lineId AND line.type = 'MA'
where address.id = 1;

I have code:

CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<AddressResult> query = cb.createQuery(AddressResult.class);
Root<Address> r = query.from(Address.class);
Join<Address, AddressLineMA >linesMA= r.join(Address_.linesMajor, JoinType.LEFT);

To get data from data base.
This query is not working as expected I get SQL like this:

select * from Address address left outer join  AddressLine line 
              on line.id = address.lineId 
    where address.id = 1;

AND line.type = ‘MA’ is missing. Does some one knows how to fix this?

My AddressLineMA.class looks like this:

@Entity
@DiscriminatorValue(value = "MA")
public class AddressLineMA extends AddressLine {

}
@Entity
@Table(name = "AddressLine")
@DiscriminatorColumn(name = "TYPE", discriminatorType = DiscriminatorType.STRING)
public abstract class AddressLine {
   private Long id;
   private String type;
   private String line;
}
  • 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-18T06:24:44+00:00Added an answer on June 18, 2026 at 6:24 am

    JPA queries always return all subclasses by default. So if you want only instances of AddressLineMA, you must change your query and relationshipto be on AddressLineMA instead of the inheritance root class, AddressLine.

    If there are other subclasses of AddressLineMA that you want to exclude, then you can use the TYPE operator added to JPA 2.0:

       query.where(cb.equal(linesMA.type(), package.AddressLineMA.class));
    

    Unfortunately, adding it into the ON clause is only supported in the yet to be released JPA 2.1 spec:

       linesMA.on(cb.equal(linesMA.type(), package.AddressLineMA.class));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SELECT *, SUM( cardtype.price - cardtype.cost ) AS profit FROM user LEFT OUTER JOIN
I want to join two tables using JPQL : SELECT * FROM A LEFT
Possible Duplicate: How to join data frames in R (inner, outer, left, right)? This
I'm having trouble optimizing this query: SELECT a.id FROM a JOIN b ON a.id=b.id
I'm trying to retrieve books from one table and left join the chapters table.
My T-SQL statement A returns 1100 rows when I add an extra JOIN in.
What's the difference between the following two SQLs: select ... from table1 t1 left
Here is the my previous experiences about optimizing sql join: in MySQL, to have
I have a simple where clause on a keyed field, a join between two
Is it possible to do a left join like this in Nhibernate: SELECT T.title_id,

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.