I am currently writing a webapp for my university project. It's a system that allows to create, modify and take language tests. My teacher was interested in my question search module. For DB I use MongoDB. He asked me what if there were 5kk records to view in the browser? He advised me to do some aggregation in MongoDB.
I have to make a search method which will allow me to search by 1 to 5 criteria from the collection documents: category, question, difficulty, question type, number of correct answers. And of course view it in the browser.
At first I tried basic operations like making a new query with criteria, but I need it to work on any number of criteria not all or one. If 1 or more fields are empty they shouldn't be considered in the search, so I'm trying to do an aggregation, but I can't get it to work and don't know if what I am trying to acomplish is even possible with this method.
And here's my problem. In DAO I try to define a aggregation but it doesn't recognize group and where methods for the class(method is undefined).
Here's my code :
public List<Question> findQuestions(Question question) {
String questionPattern = question.getQuestion().length() == 0 ? ".*" : ".*" + question.getQuestion() + ".*";
TypedAggregation<Question> agg = newAggregation(Question.class, group("category"),
match(where("category").is(question.getCategory()))
);
AggregationResults<Question> result = mongoTemplate.aggregate(agg, Question.class);
List<Question> stateStatsList = result.getMappedResults();
}
and pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pgs.languageskillchecker</groupId>
<artifactId>LanguageSkillChecker</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>LanguageSkillChecker</name>
<url>http://maven.apache.org</url>
<properties>
<spring.version>3.1.2.RELEASE</spring.version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<!-- Velocity -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<!-- Jackson -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.12</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<!-- MongoDB -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.3.3.RELEASE</version>
</dependency>
<!-- Sitemesh -->
<dependency>
<groupId>org.sitemesh</groupId>
<artifactId>sitemesh</artifactId>
<version>3.0-alpha-1</version>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.10</version>
</dependency>
<!-- poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<!-- File upload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
<build>
<finalName>LanguageSkillChecker</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
I of course import the required libraries:
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.aggregation.TypedAggregation;
import org.springframework.data.mongodb.core.aggregation.Aggregation.*;
I took the aggregation code from Spring IO Docs, but I can't get it to work properly. I'll appreciate any help ^^
And here's my problem. In DAO I try to define a aggregation but it
doesn't recognize group and where methods for the class(method is
undefined).
Those methods (where and group) are static and defined in the Criteria and Aggregation classes - you're just missing a static import.
import static org.springframework.data.mongodb.core.aggregation.Aggregation.*;
import static org.springframework.data.mongodb.core.query.Criteria.*;
or more specifically
import static org.springframework.data.mongodb.core.aggregation.Aggregation.group;
import static org.springframework.data.mongodb.core.query.Criteria.where;
You should take a look at Spring Data Specifications and Querydsl, google helps you to find examples how to create custom search based on dynamic criteria range.
http://spring.io/blog/2011/04/26/advanced-spring-data-jpa-specifications-and-querydsl/
Related
I'm building a basic web app using JSF and spring using IntelliJ IDEA. So I followed this post to config the IDEA with tomcat. But when I run the app, it takes too much time to build saying coping resources.(like 1/2 an hour) And when I make a change it takes much longer time. Strangest thing is, after the build, there are ~2GB files inside the target folder. And the same classes folders are recursively copied in to it. which means target\classes\classes\artifacts\java_test_war_exploded\WEB-INF\classes\target\classes\target\classes\target\m2e-wtp\web-resources\META-INF\maven\java_test\...etc. This goes to like infinity!
What is the problem here? Please someone help!
(sorry for my English)
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>java_test</groupId>
<artifactId>java_test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- Spring -->
<spring-framework.version>4.0.3.RELEASE</spring-framework.version>
<aspectj.version>1.7.4</aspectj.version>
<!-- Hibernate / JPA -->
<hibernate.version>4.3.5.Final</hibernate.version>
<!-- JSF Version -->
<jsf.version>2.2.10</jsf.version>
</properties>
<dependencies>
<!-- Spring and Transactions -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<!-- #Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<!-- Spring ORM support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<!-- JSF Dependencies -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>${jsf.version}</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>${jsf.version}</version>
</dependency>
<!-- http://repo1.maven.org/maven -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>com.sun.el</groupId>
<artifactId>el-ri</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
I still couldn’t find a solution for this. So I just deleted the .idea directory from the project and reimported the project to IntelliJ. Then it worked!
I have faced this problem. At first check your project folder's size. If it is too large and it is not normal (my target folder was more than ~ 2 GB) , we have a same problem!
My mistake which caused this problem was that in intellij idea, I had refactored so many packages and changed folder's directions so many at the beginning of my project. My IDE confused and made a lot of same folders in each folder and continued it many many times! Like taking selfie in front of a mirror! what will happen to your pic? it will repeat infinitely.
my solution: create my project again as same as the previous one. but by taking care and not refactoring!
Just this!
I'd like to share with you a weird experience I had today when I was trying to execute with maven unit tests for a multi-modules project.
When I ran the tests directly from the IDE (IntelliJ), everything works perfectly. But with Maven only one test class was being executed. I spend hours trying to figure out the reason for this behaviour. It turns out that only the methods whose name start with testxxx () are executed.
I'm very suprised because I knew about the naming convention at class level, but was not aware about a naming convention at method level.
Can you understand what happens?
Here the stack I'm working with: Maven 3.6.0, JUnit 5, maven-surefire-plugin:3.0.0
Edit: here the dependency section of the POM of the parent level :
<dependencyManagement>
<dependencies>
<!-- ========== Modules ========== -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>myerp-technical</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>myerp-model</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>myerp-consumer</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>myerp-business</artifactId>
<version>${project.version}</version>
</dependency>
<!-- ========== Libraries ========== -->
<!-- ===== Log4j ===== -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- Commons Logging Bridge -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- Log4j 2 SLF4J Binding -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- ===== JSR 303 - Bean validation ===== -->
<!-- interface -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<!--implementation-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
</dependency>
<!-- ===== Apache Commons ===== -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<!-- ===== Spring IOC ===== -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
<!-- ===== Spring JDBC/Tx ===== -->
<!-- spring-tx : transaction, JCA, DAO -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
<!-- spring-jdbc : commons-exceptions, datasource management -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
<scope>compile</scope>
</dependency>
<!-- ===== Database ===== -->
<!-- DB Connection pool -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.1.1</version>
</dependency>
<!-- JDBC Drivers : PostgreSQL -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1212</version>
<scope>runtime</scope>
</dependency>
<!-- ===== unit tests===== -->
<dependency>
<groupId>com.github.sbrannen</groupId>
<artifactId>spring-test-junit5</artifactId>
<version>1.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
And here an example of a class test, which is being ignored because the test method doesn't start with testXXXX():
package com.dummy.myerp.model.bean.comptabilite;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestDummy {
#Test
public void getByNumeroTest() {
Integer numero1 = 1232;
Integer numero2 = 92837;
Integer numero3 = null;
String libellé1 = "apports en capital";
String libellé2 = null;
String libellé3 = "produits exceptionnels";
CompteComptable compteComptable1 = new CompteComptable(numero1, libellé1);
CompteComptable compteComptable2 = new CompteComptable(numero2, libellé2);
CompteComptable compteComptable3 = new CompteComptable(numero3, libellé3);
List<CompteComptable> list3elements = new ArrayList<CompteComptable>(
Arrays.asList(compteComptable1, compteComptable2, compteComptable3));
assertEquals(compteComptable1, CompteComptable.getByNumero(list3elements, numero1), "3 elements, standard");
assertEquals(compteComptable2, CompteComptable.getByNumero(list3elements, numero2), "3 elements, name is null");
assertEquals(null, CompteComptable.getByNumero(list3elements, numero3), "3 elements, account is null");
assertEquals(null, CompteComptable.getByNumero(list3elements, 5555), "3 elements, account not available");
}
}
Add include section to the surefire plugin configuration.
Example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<includes>*</includes>
<properties>
<configurationParameters>
junit.jupiter.extensions.autodetection.enabled = true
</configurationParameters>
</properties>
</configuration>
</plugin>
I want to use one of the examples to launch a FrameworkFactory. Either my compiler refuses to compile ...
Map<String,String> props=new HashMap<String,String>();
props.put("org.osgi.framework.storage","target/osgi-store");
props.put("org.osgi.framework.storage.clean","onFirstInit");
FrameworkFactory factory=ServiceLoader.load(FrameworkFactory.class);
// Type mismatch: cannot convert from ServiceLoader<FrameworkFactory> to FrameworkFactory
or the vm fails load a factory ...
ServiceLoader<FrameworkFactory> loader = ServiceLoader.load(FrameworkFactory.class);
Iterator<FrameworkFactory> iter = loader.iterator();
FrameworkFactory ff = iter.next(); // there is no "next"
This is my pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>prices.otemba.org</groupId>
<artifactId>PricesFromOtemba</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<configuration>
<fork>true</fork>
<executable>C:\Program Files\Java\jdk1.8.0_60\bin\javac.exe</executable>
</configuration>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>4.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.gogo.runtime</artifactId>
<version>0.16.2</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>
If you have a suggestion concerning my pom in general then please feel free to advice.
So the following entry:
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.3.0</version>
</dependency>
Adds the OSGi 4.3 API to your project (note that 4.3.1 or higher is needed for generics to work). This is providing you with the FrameworkFactory interface, but no implementation for the service loader to find. To get an implementation you need to have an OSGi R4.3 (or higher) framework on your class path at runtime.
For example to add the Apache Felix framework R6 implementation (which is backward compatible with the R4.3 API) you would add:
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>5.0.1</version>
<!-- You aren't compiling against Felix, just using it at runtime -->
<scope>runtime</scope>
</dependency>
I would also suggest removing the following:
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
<version>1.4.0</version>
</dependency>
The reason you should remove this is that it is a much older version of the OSGi API jar. It doesn't contain the FrameworkFactory interface (it predates it) and it will clash with the OSGi 4.3 API that is also on your compilation path.
So my question is about java.util.ServiceLoader
The documentation states: "It searches for service providers on your application's class path". I built the examples and have strong doubts about that statement. The examples need to be assembled in a .jar with a subdirectory in the META-INF, having the full qualified name of the service.
In this case that would be the full qualified name of the class that implements org.osgi.framework.launch.FrameworkFactory.
So I checked my M2 repository if the bundle org.osgi.core has such an entry. The answer is no.
Conclusion: The examples that I used are not suitable for bundles that were not prepared for java.util.ServiceLoader
I'm writing a blogging application in Java that is using Spring MVC and Spring Security. I've gotten Spring Security configured, but I'm running into an issue where my application cannot resolve any class in the org.springframework.security package. When I try to compile after importing anything from this package, I get the following error:
package org.springframework.security does not exist
Right now I'm trying to implement my own user service details class and I cannot import the UserServiceDetails interface as a result of this.
This is my pom.xml (please excuse the disorganization):
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"bxsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>appname</groupId>
<artifactId>appname</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>sblog</name>
<url>http://maven.apache.org</url>
<properties>
<spring.version>3.2.5.RELEASE</spring.version>
<hibernate.version>4.2.2.Final</hibernate.version>
<mysql.version>5.1.25</mysql.version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.4.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- Java EE -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- Others -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>
</dependency>
<!-- Log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
</dependency>
<!-- MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
</dependencies>
<build>
<finalName>app</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<server>localhost</server>
<path>/appname</path>
<url>http://localhost:8080/manager/text</url>
<username>admin</username>
<password>admin</password>
</configuration>
</plugin>
</plugins>
</build>
</project>
Is there anything obviously wrong with the pom that would result in there being a problem with importing anything in the org.springframework.security package?
I appreciate anyone's help!
Spring Security 3.2.0 relies on Spring Core 3.2.6. You're currently running core version 3.2.5.
You can check other dependencies for Spring Security here
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>http://repository.primefaces.org</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>
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 http://docs.oracle.com/cd/E17904_01/web.1111/e13720/using_toplink.htm 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: http://docs.oracle.com/javaee/5/api/javax/persistence/package-summary.html
[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.