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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:32:07+00:00 2026-06-18T07:32:07+00:00

Using JPA2.0 (via Hibernate 4), I can query the database for a record where

  • 0

Using JPA2.0 (via Hibernate 4), I can query the database for a record where the query criteria is the primary key by using EntityManager.find(java.lang.Class entityClass, java.lang.Object primaryKey). But if the query criteria isn’t a primary key (for example, select all records whose city value is ‘london’), do I have to create a TypedQuery and explicitly provide the SQL statement? Is there any best practice I should adopt?

  • 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-18T07:32:09+00:00Added an answer on June 18, 2026 at 7:32 am

    The JPA Criteria API provides you with a level of compile-time safety you won’t get with constructing your own dynamic queries (using jpql or sql). Especially when a lot of conditions start to creep in (optional fields, conditional subqueries, …) it can become very easy to make mistakes.

    The Criteria API can be more complex to write (especially for simple queries), and you need to create some plumbing code around the criteria API to make it a truly dynamic and easy to use language. It doesn’t really offer it out of the box.

    Some people like working with the Criteria API, while others prefer named queries / JPQL.

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

Sidebar

Related Questions

I am developing a tool that handles some database entities using JPA2, with hibernate
I am using Java EE 6 with JBOSS7 and JPA2 + Hibernate. For my
I am building a Java application using JPA2 and Hibernate 4.0 I have a
I'm using JPA2 with hibernate 3.6.1. and a Derby database and I used the
I am trying to design an entity model using JPA2.0 via hibernate. I have
I am using JSF2 with Pure JPA2. But the problem is with entityManager, @PersistenceContext
I am using Spring 3.0 + JPA2 + Hibernate 4.1 with MySQL 5.5 I
I have an application using Spring 3.0.5, JPA2 and Hibernate 3.6.7. Maven's handling my
Hi I am using JPA2 with Hibernate implementation and I got a simple mapping
I'm using JPA2/hibernate with this data model: class Stock { @ManyToOne private StockGroup stockGroup;

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.