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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:19:12+00:00 2026-06-07T04:19:12+00:00

Using an EntityManager in an abstract class, I am trying to create a function

  • 0

Using an EntityManager in an abstract class, I am trying to create a function that returns a list of all the results in a table from the entity class. Each table has its own persistence class that inherits from the abstract class. So far I have:

public abstract class AbstractFacade<T> {
    private Class<T> entityClass;

    ...

    public List<T> findAll() {
        javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
        cq.select(cq.from(entityClass));
        return getEntityManager().createQuery(cq).getResultList();
    }
}

That works for JPA 2.0 but I just discovered that my server is restricted to JPA 1.0 which doesn’t support getCriteriaBuilder() or createQuery(CriteriaQuery cq)

Is there a way I can re-factor my code to do relatively the same thing with a mechanism that exists in JPA 1.0?

  • 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-07T04:19:14+00:00Added an answer on June 7, 2026 at 4:19 am

    You can use the following approach:

    public List<T> findAll() {
        return (List<T>) getEntityManager().createQuery(
            "select e from " + entityClass.getSimpleName() + " e")
            .getResultList();
    }
    

    Note that it won’t work if you override logical entity names (@Entity(name = ...)), but it’s not a common case in practice.

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

Sidebar

Related Questions

I'm trying to inject EntityManager in my DAO using EJB @Entity public class Book
I am trying to set up Entity Inheritance using JPA annotations and abstract classes.
I'm using ptr_map from boost for storing objects derived from some base abstract type.
Using Hibernate EntityManager 3.5.3-Final together with Unitils 3.1 results in: unitilsAfterTestTearDown(com.unifiedpost.payments.model.TestAccount) Time elapsed: 0.02
I've made an entity read-only after retrieving it using: Session session = (Session)entityManager.getDelegate(); session.setReadOnly(
I am using EntityManager for database operations. I want to execute stored procedure using
I'm using the EntityManager to persist data into my database. public void save(X x){
Using the JPA EntityManager and the JPA Query object, how can I override something
I'm using EJB3 and I have a problem related to refreshing my EntityManager .
I am using JSF2 with Pure JPA2. But the problem is with entityManager, @PersistenceContext

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.