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

  • Home
  • SEARCH
  • 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 1011195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:11:54+00:00 2026-05-16T09:11:54+00:00

Is the criteria api of eclipselink jpa2 supported for java se 6 projects? If

  • 0

Is the criteria api of eclipselink jpa2 supported for java se 6 projects? If not, that’s my problem.
Do I need to specify anything special to the criteria api in the persistence.xml?

This is my criteria query:

 final EntityType<Meaning> Meaning_ = em.getMetamodel().entity(Meaning.class);
    final CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Integer> cq = cb.createQuery(Integer.class);
    final Root<Meaning> meng = cq.from(Meaning.class);
    cq.where(meng.get(Meaning_.lastPublishedDate)); //this attributes are not recognized/found
    cq.select(meng.get(Meaning_.objId));            // "                "                   
    TypedQuery<Integer> q = em.createQuery(cq); 
    return q.getResultList();

And here is my Meaning entity:

@Entity
public class Meaning implements Serializable{
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int objId;

public int getObjId() {
    return objId;
}

@Temporal(javax.persistence.TemporalType.DATE)
private Date lastPublishedDate = null;//never

public Date getLastPublishedDate(){
        return lastPublishedDate;
    }
}
  • 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-16T09:11:55+00:00Added an answer on May 16, 2026 at 9:11 am

    About your code

    I didn’t check the correctness of the criteria query itself but, as Chris mentioned, you are mixing static metamodel classes with the EntityType that doesn’t expose what you’re looking for. Assuming your metamodel classes have been generated, remove the first line and import the generated Meaning_:

    // final EntityType<Meaning> Meaning_ = em.getMetamodel().entity(Meaning.class); 
    final CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Integer> cq = cb.createQuery(Integer.class);
    final Root<Meaning> meng = cq.from(Meaning.class);
    cq.where(meng.get(Meaning_.lastPublishedDate)); // add the appropriate import 
    cq.select(meng.get(Meaning_.objId));            
    TypedQuery<Integer> q = em.createQuery(cq); 
    return q.getResultList();
    

    About generation of the static (canonical) metamodel classes

    Here is the Maven setup I’m using to generate the canonical metamodel classes with EclipseLink:

    <project>
      ...
      <repositories>
        <!-- Repository for EclipseLink artifacts -->
        <repository>
          <id>EclipseLink Repo</id>
          <url>http://www.eclipse.org/downloads/download.php?r=1&amp;nf=1&amp;file=/rt/eclipselink/maven.repo/</url>
        </repository>    
        ...
      </repositories>
      ...
      <pluginRepositories>
        <!-- For the annotation processor plugin -->
        <pluginRepository>
          <id>maven-annotation-plugin</id>
          <url>http://maven-annotation-plugin.googlecode.com/svn/trunk/mavenrepo</url>
        </pluginRepository>
      </pluginRepositories>
      ...
      <dependencies>
        <dependency>
          <groupId>org.eclipse.persistence</groupId>
          <artifactId>eclipselink</artifactId>
          <version>2.1.0</version>
        </dependency>
        <!-- optional - only needed if you are using JPA outside of a Java EE container-->
        <dependency>
          <groupId>org.eclipse.persistence</groupId>
          <artifactId>javax.persistence</artifactId>
          <version>2.0.2</version>
        </dependency>
      <dependencies>
      ...
      <build>
        <plugins>
          <plugin>
            <groupId>org.bsc.maven</groupId>
            <artifactId>maven-processor-plugin</artifactId>
            <version>1.3.1</version>
            <executions>
              <execution>
                <id>process</id>
                <goals>
                  <goal>process</goal>
                </goals>
                <phase>generate-sources</phase>
                <configuration>
                  <!-- Without this, the annotation processor complains about persistence.xml not being present and fail -->
                  <compilerArguments>-Aeclipselink.persistencexml=src/main/resources/META-INF/persistence.xml</compilerArguments>
                  <!-- For an unknown reason, the annotation processor is not discovered, have to list it explicitly -->
                  <processors>
                    <processor>org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor</processor>
                  </processors>
                  <!-- source output directory -->
                  <outputDirectory>${project.build.directory}/generated-sources/meta-model</outputDirectory>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <inherited>true</inherited>
            <configuration>
              <source>1.6</source>
              <target>1.6</target>
              <compilerArgument>-proc:none</compilerArgument>
            </configuration>
          </plugin>
          ...
        </plugins>
      </build>
    </project>
    

    Some comments:

    • EclipseLink annotation processor is provided by the main artifact, there is no extra dependency to add.
    • For an unknown reason, the annotation processor is not discovered, I have to list it explicitly as a <processor>.
    • Without the -Aeclipselink.persistencexml, the annotation processor complains about the persistence.xml not being present and fail.
    • I prefer to generate source code under target (I want a clean to clean it).

    With this configuration, the static metamodel classes get generated and compiled appropriately.

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

Sidebar

Related Questions

I'm working with the criteria API, querying against a mapping file that I cannot
I need help with an nhibernate query. I would prefer to use Criteria API
I need to replicate the following working HQL query using criteria API. session.CreateQuery( select
I would like to use JPA2 Criteria API with metamodel objects, which seems to
I have sql that i would like to write in Criteria api: SELECT CASE
I'd like to use Hibernate's criteria api to formulate a particular query that joins
I am using JPA2 with it's Criteria API to select my entities from the
I have a problem with SetFetchMode call in Criteria API in following query: DetachedCriteria.For<User>()
I'm facing a strange issue using the Criteria API. I want to dynamically add
I'm trying to create a query with the Criteria API from JPA 2.0, 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.