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?
persistence package is used to provide an entity manager. Persistence - The Persistence is a bootstrap class which is used to obtain an EntityManagerFactory interface. createEntityManagerFactory() method - The role of this method is to create and return an EntityManagerFactory for the named persistence unit.
clear. Clear the persistence context, causing all managed entities to become detached. Changes made to entities that have not been flushed to the database will not be persisted.
In JPA, the EntityManager interface is used to allow applications to manage and search for entities in the relational database. The EntityManager is an API that manages the lifecycle of entity instances. An EntityManager object manages a set of entities that are defined by a persistence unit.
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With