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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:21:35+00:00 2026-05-30T04:21:35+00:00

I’m fighting about two days with the following problem and hope you can give

  • 0

I’m fighting about two days with the following problem and hope you can give me a push into the right direction. The tutorials and examples I found during my research always only showed how to easy joins work in the criteria api. First of all I have two classes:

@Entity
public class Offer {

  private String name;
  @ManyToOne private Location location;
  private String tags;
}

and

@Entity
public class Location {
  private String name;
  private string tags;
}

Because I need to avoid circular references the connection beween these classes is only unidirectional. There are a lot of additional attributes in this classes and I want to build dynamic queries depending on my search filter. The following SQL statement shall explain what I like to do:

SELECT l 
FROM Offer o 
JOIN o.location l
WHERE o.tags LIKE :sometag AND l.tags LIKE :someothertag

After implementing this with the criteria api I got to this code:

CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaQuery<Location> criteriaQuery = criteriaBuilder.createQuery(Location.class);
criteriaQuery = criteriaQuery.distinct(true);
Join location;
ArrayList<Predicate> whereList = new ArrayList<Predicate>();

// if filter by offer, use offer as main table and join location table
if (filter.getOfferTags() != null) {
  Root<Offer> offer = criteriaQuery.from(Offer.class);

  location = offer.join("location");


  // limit to offering tags
  Path<String> tagPath = offer.get("tags");

  for (String tag : filter.getOfferTags()) {
    Predicate whereTag = criteriaBuilder.like(tagPath, "%" + tag + "%");
    whereList.add(whereTag);
  }

} else {
  // else use location table as base
  location = (Join<Location, Location>) criteriaQuery.from(Location.class);
}

But if I execute this I get the following error message from my H2 Database:

Column "LOCATION.ID" not found; SQL statement: 
SELECT DISTINCT LOCATION.ID, LOCATION.NAME
FROM OFFER t0, LOCATION t1 
WHERE t0.TAGS LIKE ? AND t1.TAGS LIKE ?

The database expects t1.ID and t1.NAME in the select clause and not LOCATION.ID and LOCATION.NAME. How can I tell JPA to create the “right” request? Am I missing something in my code?

I’m using Glassfish 3.1.1 with Eclipse Link and an H2 Database.

  • 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-30T04:21:36+00:00Added an answer on May 30, 2026 at 4:21 am

    I think you just missed a select in your query:

    criteriaQuery.select(location);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I've tracked down a weird MySQL problem to the two different ways I was
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.