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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:27:42+00:00 2026-06-08T12:27:42+00:00

I feel like this is a silly question, but I can’t find the answer.

  • 0

I feel like this is a silly question, but I can’t find the answer. I have a class as follows:

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name="DEMO_VARIABLES")
public class Variable implements Serializable
{
    private static final long serialVersionUID = -1734898766626582592L;

    @Id
    @SequenceGenerator(name="VARIABLE_ID_GENERATOR", sequenceName="DEMO_VARIABLE_ID_SEQ", allocationSize=1)
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="VARIABLE_ID_GENERATOR")
    @Column(name="VARIABLE_ID", unique=true, nullable=false, precision=22)
    private long variableId;

    @Column(name="VARIABLE_NAME", nullable=false, length=50)
    private String variableName;

    @Column(name="VARIABLE_VALUE", nullable=false, length=500)
    private String variableValue;

    public Variable()
    {

    }

    public long getVariableId()
    {
        return variableId;
    }

    public void setVariableId(long variableId)
    {
        this.variableId = variableId;
    }

    public String getVariableName()
    {
        return variableName;
    }

    public void setVariableName(String variableName)
    {
        this.variableName = variableName;
    }

    public String getVariableValue()
    {
        return variableValue;
    }

    public void setVariableValue(String variableValue)
    {
        this.variableValue = variableValue;
    }
}

Now I want to use a criteria query to load the entire table (ie “select * from variables”). I’d like to use a criteria query more for code consistency than anything else. I get this exception though:

java.lang.IllegalStateException: No criteria query roots were specified
    at org.hibernate.ejb.criteria.CriteriaQueryImpl.validate(CriteriaQueryImpl.java:303)
    at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:145)
    at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:437

The query I am using is:

public List<Variable> loadAllVariables()
{
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Variable> query = builder.createQuery(Variable.class);

    return em.createQuery(query).getResultList();
} 

I know that the exception means it wants this:

Root<Variable> variableRoot = query.from(Variable.class);

But without a Predicate I don’t see how to get the Root object into the query?

  • 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-08T12:27:43+00:00Added an answer on June 8, 2026 at 12:27 pm

    I am not sure, did I understood you right, but if goal is to choose fetch list of all Variable entities, then following is way to go:

    public List<Variable> loadAllVariables() {
        CriteriaBuilder builder = em.getCriteriaBuilder();
        CriteriaQuery<Variable> query = builder.createQuery(Variable.class);
        Root<Variable> variableRoot = query.from(Variable.class);
        query.select(variableRoot);
    
        return em.createQuery(query).getResultList();
    } 
    

    Difference is that select is used. All implementations do not implicitly use last call of from in place of select. In JPA 2.0 specification this is told as follows:

    Portable applications should use the select or multiselect method to
    specify the query’s selection list. Applications that do not use one
    of these methods will not be portable.

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

Sidebar

Related Questions

I feel like this is a silly question but I always find that modifying
I feel silly, but I just can't find an answer to this. Let's say
I feel like this is a stupid question, but I can't think of a
I feel like this must have been asked before, but I've looked at Knockout
I feel silly for asking this but it isn't like I could google this.
I feel like this may be a dumb question, but it's late and my
This may seem like a silly question, but what are the functional differences, if
This might seem like a silly question, but after asking some questions on stackoverflow
I feel like this should be simple, but can't figure it out: What's the
I feel kind of silly asking this question as it seems really simple, but

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.