I am using Hibernate 4, Spring 3 and JSF 2.0 and Weblogic 10.3.6 I have the following in DAO class
CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Request> c = cb.createQuery(Request.class); When I run my application I am getting the following exception.
javax.persistence.EntityManager.getCriteriaBuilder()Ljavax/persistence/criteria /CriteriaBuilder; java.lang.NoSuchMethodError: javax.persistence.EntityManager.getCriteriaBuilder()Ljavax/persistence/criteria /CriteriaBuilder; at net.test.request.dao.RequestDAOImpl.getRequest(RequestDAOImpl.java:51) I did not use JPA1 jars, however I am still getting this exception. Not able to figure how to get rid of this exception. Any help is highly appreciable.
Thanks
pom.xml
<repositories> <repository> <id>prime-repo</id> <name>PrimeFaces Maven Repository</name> <url> <layout>default</layout> </repository> </repositories> <properties> <spring.version>3.1.1.RELEASE</spring.version> </properties> <dependencies> <!-- Spring 3 dependencies --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> </dependency> <!-- JSF library --> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-api</artifactId> <version>2.1.6</version> </dependency> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-impl</artifactId> <version>2.1.6</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <!-- Primefaces library --> <dependency> <groupId>org.primefaces</groupId> <artifactId>primefaces</artifactId> <version>3.4.2</version> </dependency> <dependency> <groupId>org.primefaces.themes</groupId> <artifactId>flick</artifactId> <version>1.0.8</version> </dependency> <!-- Hibernate library --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.1.0.Final</version> </dependency> <dependency> <groupId>javassist</groupId> <artifactId>javassist</artifactId> <version>3.12.1.GA</version> </dependency> <dependency> <groupId>javax.inject</groupId> <artifactId>javax.inject</artifactId> <version>1</version> </dependency> <!-- Oracle Java Connector library --> <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.3</version> </dependency> <dependency> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId> <version>0.9.1.2</version> </dependency> <!-- Log4j library --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.16</version> </dependency> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.4</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-jpamodelgen</artifactId> <version>1.2.0.Final</version> </dependency> </dependencies> <build> <resources> <resource> <directory>src/main/resources</directory> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> <compilerArgument>-proc:none</compilerArgument> </configuration> </plugin> <plugin> <groupId>org.bsc.maven</groupId> <artifactId>maven-processor-plugin</artifactId> <executions> <execution> <id>process</id> <goals> <goal>process</goal> </goals> <phase>generate-sources</phase> <configuration> <!-- source output directory --> <outputDirectory>target/metamodel</outputDirectory> </configuration> </execution> </executions> </plugin> </plugins> </build> </project> 1 Answer
The method EntityManager.getCriteriaBuilder is a part of JPA 2 (which is part of Java EE 6), which is not provided and/or turned on by default in WebLogic 10.
Here is a link which provides instructions that may fix your problem. If not, you'll need to start googling "weblogic 10 jpa 2" and see if you can find a solution that works for you.
If none of these solutions work, your last resort will be to redesign your application to only use JPA 1 methods. To use JPA 1 you must limit yourself to the classes and interfaces defined here:
[update]
Or - since you are using Hibernate anyways, don't rely so much on JPA classes. Use hibernate specific classes instead. Hibernate has had criteria since 3.x. Instead of an EntityManager you create a Hibernate session factory. Then you can do:
import org.hibernate.Criteria; import org.hibernate.Session; import org.hibernate.SessionFactory; ... Session session = sessionFactory.openSession(); Criteria crit = session.createCriteria(Person.class); Your code is now locked into using Hibernate as your persistence provider. In my case we always use Hibernate so it's not a real problem. This is a question you have to decide for yourself. If your application can tolerate being locked into Hibernate, this should give you the functionality you need while still running on WebLogic.
7