7

I am introducing JPA2.0 in my application working on Oracle9i database and I added the libraries EclipseLink(JPA2.0) and created the entity classes but when I use

javax.persistence.criteria.CriteriaQuery cq = em.getCriteriaBuilder().createQuery();

I get the following error

cannot find symbol symbol : method getCriteriaBuilder() location: interface javax.persistence.EntityManager

my web.xml is version 2.4 and here's my persistence.xml

<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
   <persistence-unit name="MiraclinPU" transaction-type="JTA">
    <jta-data-source>jdbc/Miraclin</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties/>
   </persistence-unit>
</persistence>

It looks like the app is using JPA1.0 as I read on the forums...Can anyone help?

Questionmark
  • 145
  • 1
  • 2
  • 10

5 Answers5

5

Use:

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.1.Final</version>
    </dependency>

And not:

    <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>persistence-api</artifactId>
        <version>1.0.2</version>
    </dependency>
Thys Andries Michels
  • 761
  • 4
  • 11
  • 23
4

Search in all libraries that are included in your project, and remove the ones containing persistence.xml except the one you need. Then reinclude them again.

Questionmark
  • 145
  • 1
  • 2
  • 10
2

In eclipse:

  • Project -> Properties -> Java Build Path -> Configure Build Path -> Libraries
  • remove references to javax/persistente
  • insert a reference to hibernate-jpa-2.0-api-/version/.jar

how to verify:

in your sourceDAO.java press F3 in EntityManagerFactory and look what .jar eclipse open.

Andrea
  • 11,801
  • 17
  • 65
  • 72
SauloAlessandre
  • 705
  • 7
  • 9
0

Missing

import javax.persistence.criteria.*;

possibly?

osgx
  • 90,338
  • 53
  • 357
  • 513
0

Due to org.hibernate.orm artifact was moved to hibernate-core;

I removed this from pom.xml:

<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.4.9.Final</version>
</dependency>

and added this:

<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.4.9.Final</version>
</dependency>

That was solved the cannot find symbol getCriteriaBuilder() problem.

bayram.cicek
  • 193
  • 2
  • 9