Amazon Redshift Invalid operation: column notation .id applied to type character, which is not a composite type; Spring Data JPA - amazon-web-services

I am getting an error when trying to pull from an Amazon Redshift DB and can't figure out how to fix it.
Error:
com.amazon.support.exceptions.ErrorException: [Amazon](500310) Invalid operation:
column notation .id applied to type character, which is not a composite type;
application.properties:
spring.jpa.show-sql=true
spring.datasource.url=jdbc:redshift://mydb.blah.region.redshift.amazonaws.com:5439/dev?currentSchema=myschema
spring.datasource.username=user
spring.datasource.password=pass
spring.datasource.dbcp2.validation-query=SELECT 1
Controller:
#RestController
#RequestMapping("/")
public class ContactController {
private RedshiftRepo repo;
#Autowired
public ContactController(RedshiftRepo repo) {
this.repo = repo;
}
#GetMapping(value = "/get")
public ResponseEntity<List<Contact>> getTest(){
List<Contact> list = repo.findAll();
return new ResponseEntity<List<Contact>>(list, HttpStatus.OK);
}
#GetMapping(value = "/getByEmail")
public ResponseEntity<List<Contact>> getByEmail(#RequestParam String email){
List<Contact> list = repo.getContactByEmail(email);
return new ResponseEntity<List<Contact>>(list, HttpStatus.OK);
}
}
RedshiftRepo:
#Repository
public interface RedshiftRepo extends JpaRepository<Contact, Integer>{
#Query("select id, firstname, lastname, accountid from Contact c where c.email = ?1")
public Contact getContactByEmail(String email);
}
Entity:
#Entity
#Table(name ="user")
public class Contact {
#Id
private String id;
private String firstname;
private String lastname;
private String accountid;
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.1</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.contactAPI</groupId>
<artifactId>pocContactAPI</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>pocContactAPI</name>
<description>Contact Getter</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-redshift</artifactId>
<version>1.11.999</version>
</dependency>
<dependency>
<groupId>com.amazon.redshift</groupId>
<artifactId>redshift-jdbc42-no-awssdk</artifactId>
<version>1.2.41.1065</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>redshift</id>
<url>http://redshift-maven-repository.s3-website-us-east-1.amazonaws.com/release</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
When I try to GET localhost:8080/get:
Hibernate: select c1_0.id,c1_0.firstname,c1_0.lastname,c1_0.accountid from user c1_0
com.amazon.support.exceptions.ErrorException: [Amazon](500310) Invalid operation:
column notation .id applied to type character, which is not a composite type;
Any idea what I am doing wrong?

You need to add the following dependency to your pom.xml:
(It is my understanding that this first step has already been completed by you, however I am including it for others as well.)
<dependency>
<groupId>com.amazon.redshift</groupId>
<artifactId>redshift-jdbc42-no-awssdk</artifactId>
<version>1.2.41.1065</version>
</dependency>
This will allow you to use the Redshift JDBC driver. You can find more information on this here: https://docs.aws.amazon.com/redshift/latest/mgmt/configure-jdbc-connection.html
You also need to specify the Redshift driver in your application.properties:
spring.datasource.driver-class-name=com.amazon.redshift.jdbc42.Driver
You can find more information on this here: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html#howto-initialize-a-database-using-spring-jdbc
After making these changes, I was able to run your application and get the following response:
[
{
"id": "1",
"firstname": "John",
"lastname": "Doe",
"accountid": "1"
}
]
I hope this helps!

Related

Permission denied Redshift Spring boot but works in SQL Client

I am trying to make a simple REST API to query a Redshift DB. I was granted access and can view the tables in DBeaver, but when I try to access it programmatically, I get:
Invalid operation: permission denied for relation "account"
Is this something that I am doing wrong in my code or is this a permission that I need to be granted?
For another application, we have to use AWS credentials and a AWSClientBuilder,etc. Is that the route I need to go here or can I finish my Proof of Concept with just the username and password that I use to access it on my SQL client?
Here is my code:
application.properties:
spring.jpa.show-sql=true
spring.datasource.url=jdbc:redshift://mydb.blah.region.redshift.amazonaws.com:5439/dev?currentSchema=myschema
spring.datasource.username=user
spring.datasource.password=pass
spring.datasource.dbcp2.validation-query=SELECT 1
spring.datasource.driver-class-name=com.amazon.redshift.jdbc42.Driver
I have also tried adding ;UID=user;PWD=pass; to the end of the datasource.url, but didn't change anything.
Controller:
#RestController
#RequestMapping("/")
public class ContactController {
private RedshiftRepo repo;
#Autowired
public ContactController(RedshiftRepo repo) {
this.repo = repo;
}
#GetMapping(value = "/get")
public ResponseEntity<List<Contact>> getTest(){
List<Contact> list = repo.findAll();
return new ResponseEntity<List<Contact>>(list, HttpStatus.OK);
}
#GetMapping(value = "/getByEmail")
public ResponseEntity<List<Contact>> getByEmail(#RequestParam String email){
List<Contact> list = repo.getContactByEmail(email);
return new ResponseEntity<List<Contact>>(list, HttpStatus.OK);
}
}
RedshiftRepo:
#Repository
public interface RedshiftRepo extends JpaRepository<Contact, Integer>{
#Query("select id, firstname, lastname, accountid from Contact c where c.email = ?1")
public Contact getContactByEmail(String email);
}
Entity:
#Entity
#Table(name ="account")
public class Contact {
#Id
private String id;
private String firstname;
private String lastname;
private String accountid;
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.1</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.contactAPI</groupId>
<artifactId>pocContactAPI</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>pocContactAPI</name>
<description>Contact Getter</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-redshift</artifactId>
<version>1.11.999</version>
</dependency>
<dependency>
<groupId>com.amazon.redshift</groupId>
<artifactId>redshift-jdbc42-no-awssdk</artifactId>
<version>1.2.41.1065</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>redshift</id>
<url>http://redshift-maven-repository.s3-website-us-east-1.amazonaws.com/release</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

Service could not find resource (Wildfly 10.0, JAX-RS)

I am learning REST services and face the problem: RestEasy cannot find my resources, even though I've tried various ways to demonstrate them.
Exception:
Failed to execute: javax.ws.rs.NotFoundException: RESTEASY003210: Could not find resource for full path: http://localhost:8080/RestfullService/services/hello
where RestfullService is the name of my project, /service - applicationPath, hello - resource. None of the errors (404 etc.) are shown on this pages.
My web.xml
(by the way, I've met controversial approaches regarding the content of web.xml while using web app server 3.0. According to official manuals, it is not required, but lots of people argue for it. What is the best practice?)
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>RestEasy sample Web Application</display-name>
<listener>
<listener-class>
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<servlet>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.store.model.WebConfig</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/</param-value>
</context-param>
</web-app>
My pom.xml (Although I've added all dependencies manually, the problem wasn't eliminated)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>RestfullService</groupId>
<artifactId>RestfullService</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>webapp\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- <executions> <execution> <phase>package</phase> <configuration> <webXml>\webapp\WEB-INF\web.xml</webXml>
</configuration> </execution> </executions> -->
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.7</version>
<configuration>
<modules>
<ejbModule>
<!-- property configurations goes here -->
</ejbModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>JBoss repository</id>
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.4.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>3.0.4.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-servlet-initializer</artifactId>
<version>3.0.4.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.4.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>3.0.4.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>jaxrs-api</artifactId>
<version>3.0.4.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
<version>3.0.4.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-7.0</artifactId>
<version>1.0.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>
<artifactId>jboss-annotations-api_1.2_spec</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0-EDR1</version>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
<version>1.0.2.Final</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
</dependencies>
</project>
ServiceInitialisation.java (both options with and without the body of this class didn't help):
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
#ApplicationPath("/services")
public class ServiceInitialisation extends Application{
// private Set<Object> singletons = new HashSet<Object>();
// private Set<Class<?>> classes = new HashSet<Class<?>>();
//
// public ServiceInitialisation() {
// singletons.add(new GoodsWebServiceImpl());
// }
//
// #Override
// public Set<Object> getSingletons() {
// return singletons;
// }
//
// #Override
// public Set<Class<?>> getClasses() {
// return classes;
// }
}
And finally services:
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import com.store.entity.Item;
#Path("/")
public interface GoodsWebService {
#GET
#Path("/hello")
#Produces("application/json")
public Response greet();
// id: \\d+ - regex for cheching if it is int #GET #Path("{id:
\\d+}")
#Produces("application/json")
public Response
getInfoById(#PathParam("id") int id);
#GET
#Path("/all")
#Produces("application/json")
public List<Item> getAllItems();
}
package com.store.restService;
import java.util.ArrayList;
import java.util.List;
//import org.json.JSONException;
//import org.json.JSONObject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import org.json.JSONObject;
import com.store.entity.Item;
import com.store.entity.Shop;
#Path("/")
public class GoodsWebServiceImpl implements GoodsWebService
{
private static List<Item>data;
private static List<Shop>shops1;
private static List<Shop>shops2;
private static List<Shop>shops3;
private static Shop shop1;
private static Shop shop2;
private static Shop shop3;
static {
shop1 = new Shop(1,4.55, 1);
shop2 = new Shop(2,9.99, 2);
shop3 = new Shop(3,6,0);
shops1.add(shop1); shops1.add(shop2);
shops2.add(shop3); shops2.add(shop1);
shops3.add(shop2); shops3.add(shop3);
data = new ArrayList<>();
data.add(new Item(1, "hand", shops1));
data.add(new Item(2, "pen", shops2));
data.add(new Item(3, "ball", shops2));
}
public static Item getItemById(int id){
for(Item e: data){
if(e.getId()==id) return e;
}
throw new RuntimeException("Can't find Item with id -" + id);
}
public static List<Item> getAll(){
return data;
}
#Override
public Response greet(){
String result = "Hello!";
return Response.status(200).entity(result).build();
}
#Override
public Response getInfoById(int id){
JSONObject jsonObject = new JSONObject();
Item item = getItemById(id);
jsonObject.put("Id ", item.getId());
jsonObject.put("Mpn ", item.getMpn());
jsonObject.put("Shop ", item.getShops());
String result = "Output:\n" + jsonObject;
return Response.status(200).entity(result).build();
}
#Override
public List<Item> getAllItems(){
// JSONObject jsonObject = new JSONObject();
// List<Item> items = getAll();
// jsonObject.put("List", items);
// JSONArray jArray = jsonObject.getJSONArray("List");
// for(int i=0; i<jArray.length(); i++){
// System.out.println(jArray.getJSONObject(i).getString("id"));
// System.out.println(jArray.getJSONObject(i).getString("mpn"));
// System.out.println(jArray.getJSONObject(i).getString("shop"));
// }
return getAll();
}
}
I would be gratefull for any comments, since all the available solutions in the web were already been unsuccessfully tried.
Thanks in advanced
Update:
Due to the fact that only a few manuals were succesfully deployed on my machine, I suppose I choose incorrect setting during the process of creation of the project.
I create the project for REST in this way: create Dynamic web project -> convert it to Maven -> add dependencies etc. -> trying to deploy
Screenshot of them:
The image is here
Update2
Moreover, I've noticed that every time I start WildFly I meet the same error. I have tried to create a few project with various dependencies, but the result is the same. How to deal with it?
22:45:09,109 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC000001: Failed to start service jboss.deployment.unit."RestService.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."RestService.war".POST_MODULE: WFLYSRV0153: Failed to process phase POST_MODULE of deployment "RestService.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:163)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer from [Module "deployment.RestService.war:main" from Service Module Loader]
at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.checkDeclaredApplicationClassAsServlet(JaxrsScanningProcessor.java:292)
at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.scanWebDeployment(JaxrsScanningProcessor.java:153)
at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.deploy(JaxrsScanningProcessor.java:104)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:156)
... 5 more
Caused by: java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer from [Module "deployment.RestService.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)
at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.checkDeclaredApplicationClassAsServlet(JaxrsScanningProcessor.java:290)
... 8 more
22:45:09,114 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 1) WFLYCTL0013: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"RestService.war\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"RestService.war\".POST_MODULE: WFLYSRV0153: Failed to process phase POST_MODULE of deployment \"RestService.war\"
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer from [Module \"deployment.RestService.war:main\" from Service Module Loader]
Caused by: java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer from [Module \"deployment.RestService.war:main\" from Service Module Loader]"}}
You don't need web.xml, the resteasy-servlet, or any explicit RESTEasy dependencies in your POM.
You'd better start with a simple working example, e.g. https://github.com/wildfly/quickstart/tree/10.x/jaxrs-client.
Despite its name, this sample not only includes a JAX-RS client, but also a JAX-RS service.

Spring Data Neo4J template.fetch() not returning entire collection

I am completely baffled by this, and am not sure what else I can do to get this to work.
Using #Fetch on a relationship, will eagerly fetch that relationship.
Template.fetch can be used to fetch a relationship, if the property is not annotated with #fetch, i.e lazy loading. Does this type of lazy loading work with sets?
I have a node entity called Project, which has a set of scans. When I try to fetch the set of scans I only get 1 scan. When I modify the Project class to use #Fetch, I get 3 scans. The right amount of scans is 3. Using template.fetch is not giving me the entire collection. The question is why? Is there something wrong in my code?
The issue here is ProjectServiceImpl.findAllScans();
Below is my source code, starting with my maven pom file.
<!-- Spring Version -->
<properties>
<java-version>1.8</java-version>
<spring.version>4.0.9.RELEASE</spring.version>
<spring.security.version>3.2.5.RELEASE</spring.security.version>
<jackson.version>2.3.0</jackson.version>
<guava.version>15.0</guava.version>
<spring.neo4j.version>3.1.5.RELEASE</spring.neo4j.version>
<spring.mongodb.version>1.6.2.RELEASE</spring.mongodb.version>
<ehcache.version>2.9.0</ehcache.version>
<logback.version>1.1.2</logback.version>
<jcloverslf4j.version>1.7.10</jcloverslf4j.version>
<javax.servlet.version>3.1.0</javax.servlet.version>
<javax.validation.version>1.1.0.Final</javax.validation.version>
<spring.swagger.version>1.0.0</spring.swagger.version>
<spring.swagger.ui.version>0.4</spring.swagger.ui.version>
</properties>
<repositories>
<repository>
<id>jcenter-release</id>
<name>jcenter</name>
<url>http://oss.jfrog.org/artifactory/oss-release-local/</url>
</repository>
<repository>
<id>oss-jfrog-artifactory</id>
<name>oss-jfrog-artifactory-releases</name>
<url>http://oss.jfrog.org/artifactory/oss-release-local</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.ajar</groupId>
<artifactId>swagger-spring-mvc-ui</artifactId>
<version>${spring.swagger.ui.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.mangofactory</groupId>
<artifactId>swagger-springmvc</artifactId>
<version>${spring.swagger.version}</version>
</dependency>
<!-- Spring Framework Core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</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-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Jackson JSON Dependencies-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<!-- Servlet 3.1 and Java EE Validation API-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax.servlet.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>${javax.validation.version}</version>
</dependency>
<!-- Spring Data MongoDB -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>${spring.mongodb.version}</version>
</dependency>
<!-- Spring Data Neo4J -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>${spring.neo4j.version}</version>
</dependency>
<!-- Ehcache -->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>${ehcache.version}</version>
</dependency>
<!-- Google Guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<!-- Logback -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${jcloverslf4j.version}</version>
</dependency>
</dependencies>
<build>
<finalName>TEST</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
The Project Pojo:
#NodeEntity
public class Project {
// Properties
#GraphId
private Long id;
#Indexed(unique = true)
private String name;
#Indexed
private String xxxxId;
// Relationships
#RelatedTo(type = "HAS_SCAN", elementClass = Scan.class)
private Set<Scan> scans;
The next code snippet below is the scan class I use.
#NodeEntity
public class Scan {
// Properties
#GraphId
private Long id;
#Indexed
private String xxxxId;
#Indexed
private String projectVersion;
#Indexed
private Date date;
//Relationships
#RelatedTo(type = "NEXT_SCAN")
private Scan scan;
#RelatedTo(type = "HAS_ISSUE", elementClass = Issue.class)
private Set<Issue> issues;
#RelatedTo(type = "HAS_DEPENDENCY", elementClass = Dependency.class)
private Set<Dependency> dependencies;
#RelatedTo(type = "HAS_PACKAGE", elementClass = Package.class)
private Set<Package> packages;
The next code snippet below is the repository class I use.
#Repository
public interface ProjectRepository extends GraphRepository<Project> {
#Query("MATCH (p:Project) RETURN p")
public Set<Project> findAllProjects();
#Query("MATCH (p:Project {xxxId:{0}}) RETURN p")
public Project findProjectById(String projectId);
}
The class below is snippet of the service class I use, where I am calling template.fetch
#Service
#Transactional
public class ProjectServiceImpl implements ProjectService {
#Autowired
private Neo4jTemplate template;
#Autowired
private ProjectRepository projectRepository;
#Autowired
private ScanRepository scanRepository;
private static final Logger LOGGER = LoggerFactory.getLogger(ProjectServiceImpl.class);
#Override
public ProjectsDTO findAllProjects() {
return DTOTransformerUtil.transformProjectSetToProjectsDTO(projectRepository.findAllProjects());
}
#Override
public ProjectDTO findProject(String projectId) {
if (projectId != null) {
return DTOTransformerUtil.transformProjectToProjectDTO(projectRepository.findProjectById(projectId));
}
return null;
}
#Override
public ScansDTO findAllScans(String projectId) {
if (projectId != null) {
Project project = projectRepository.findProjectById(projectId);
return DTOTransformerUtil.transformScanSetToScansDTO(template.fetch(project.getScans()));
}
return null;
}
I am completely lost as to what the issue maybe be, i am currently trying older version of Spring data neo4j, maybe that may help resolve the issue.

Why the arquillian gives me that : Could not read active container configuration?

I try to integrate the arquillian solution into my maven EJB project which contains juste the EJBs which I uses in other separate projects.
I use Jboss EAP6.
So i have make it as the following :
I made the arquillian.xml into ejbModule/src/test/resources/:
<container qualifier="jboss" default="true">
<configuration>
<property name="jbossHome">D:\jbdevstudio\jboss-eap-6.2</property>
</configuration>
</container>
in the pom of my project i added the following dependencies:
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-jbossas-embedded-6</artifactId>
<version>1.0.0.Alpha5</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-junit</artifactId>
<version>1.0.0.Alpha5</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
<profiles>
<profile>
<id>jbossas-embedded-6</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>arq-jbossas-managed</id>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-containermanaged</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>arq-jbossas-remote</id>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-containerremote</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
The Test Class :
import javax.inject.Inject;
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.oap.subscription.AbstractSubscription;
#RunWith(Arquillian.class)
public class SubscriptionFactoryTest {
#Inject
private SubscriptionFactory subscriptionFactory;
#Deployment
public static JavaArchive getDeployement() {
System.out.println("### testSayHelloEJB");
return ShrinkWrap.create(JavaArchive.class, "subscriptionFactory.jar")
.addClasses(AbstractSubscription.class,SubscriptionFactory.class);
}
#Test
public void getSubscriptionByIdTest() {
System.out.println("### testSayHelloEJB");
}
}
The EJB Class:
#Remote(ISubscriptionFactoryRemote.class)
#Local(ISubscriptionFactoryLocal.class)
#Stateless
public class SubscriptionFactory extends AbstractSubscription implements ISubscriptionFactoryRemote {
#Override
public AbstractSubscription getSubscriptionById(final Integer id) {
AbstractSubscription ret = null;
if (id != null) {
// create query
final StringBuilder queryString = new StringBuilder("select c from AbstractSubscription c ");
try {
queryString.append("where c.id = :id");
// create query
Query query = this.getEntityManager().createQuery(queryString.toString());
// set parameter
query = query.setParameter("id", id);
// recovers refCountry
ret = (AbstractSubscription) query.getSingleResult();
} catch (final Exception exc) {
}
}
return ret;
}
}
When i run the class test as Junit test , it gives me the errors :
janv. 20, 2015 12:15:34 PM org.jboss.arquillian.impl.client.container.ContainerRegistryCreator getActivatedConfiguration
Infos: Could not read active container configuration: null
the Faillure Trace:
java.lang.NoClassDefFoundError: Lorg/jboss/embedded/api/server/JBossASEmbeddedServer;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2397)
at java.lang.Class.getDeclaredFields(Class.java:1806)
at org.jboss.arquillian.impl.core.Reflections.getFieldInjectionPoints(Reflections.java:74)
... 79 more
Any idea.
You're using a very old version of Arquillian, I'd use at least version 1.1.0.Final. I also don't think you need a few of the Arquillian dependencies you have defined.
Remove the arquillian-jbossas-embedded-6 and arquillian-junit depdendencies.
There are plenty of quickstart examples of how to use Arquillian with JBoss EAP. Have a look at some of the pom's there as it might help.

JUnit spring testing dao hibernate

I'm trying test my application using JUnit but I've got error like this:
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from URL [file:src/main/webapp/WEB-INF/spring/root-context.xml]
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from URL [file:src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml]
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
INFO : org.springframework.context.support.GenericApplicationContext - Refreshing org.springframework.context.support.GenericApplicationContext#1cec6b00: startup date [Fri Jan 03 14:06:23 CET 2014]; root of context hierarchy
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO : org.springframework.context.support.GenericApplicationContext - Bean 'dataSource' of type [class org.apache.commons.dbcp.BasicDataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO : org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.5.6-Final
INFO : org.hibernate.cfg.Environment - Hibernate 3.5.6-Final
INFO : org.hibernate.cfg.Environment - hibernate.properties not found
INFO : org.hibernate.cfg.Environment - Bytecode provider name : javassist
INFO : org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
INFO : org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
INFO : org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.cebul.jez.entity.Adresy
INFO : org.hibernate.cfg.annotations.EntityBinder - Bind entity com.cebul.jez.entity.Adresy on table Adresy
INFO : org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.cebul.jez.entity.DokumentZamowienia
INFO : org.hibernate.cfg.annotations.EntityBinder - Bind entity com.cebul.jez.entity.DokumentZamowienia on table DokumentZamowienia
INFO : org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.cebul.jez.entity.Hist_Wyszuk
INFO : org.hibernate.cfg.annotations.EntityBinder - Bind entity com.cebul.jez.entity.Hist_Wyszuk on table Hist_Wyszuk
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#68a0864f: defining beans [dataSource,sessionFactory,transactionManager,org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0,mailSender,org.springframework.webflow.mvc.servlet.FlowHandlerMapping#0,org.springframework.webflow.mvc.servlet.FlowHandlerAdapter#0,flowExecutor,org.springframework.binding.convert.service.DefaultConversionService#0,org.springframework.webflow.expression.spel.WebFlowSpringELExpressionParser#0,org.springframework.webflow.mvc.builder.MvcViewFactoryCreator#0,org.springframework.webflow.engine.builder.support.FlowBuilderServices#0,flowRegistry,multipartResolver,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,hibernateTestConfig,testConfig,kategorieDao,komentarzeDao,produktyDao,testDatabaseDao,userDao,zamowienieDao,zdjecieDao,kategorieService,komentarzeService,platnoscConverter,produktyService,testDataBaseService,userService,zamowienieService,zdjecieService,mail,scopedTarget.shoppingCart,shoppingCart,flowDodajProdukt,koszykBeanFlow,scopedTarget.userShortInfo,userShortInfo,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,adminHomeController,AdminPanelController,dodajProduktyController,homeController,komentarzController,koszykController,logController,MojeKontoController,produktyController,registerController,szukajController,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,org.springframework.web.servlet.view.InternalResourceViewResolver#0,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0,proxyTransactionManagementConfiguration,transactionAttributeSource,transactionInterceptor,entityManagerFactoryBean,exceptionTranslation,getMyService]; root of factory hierarchy
ERROR: org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener#2200c550] to prepare test instance [com.cebul.jez.model.UserDaoTest#609a18a0]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122)
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:105)
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:74)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:312)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in URL [file:src/main/webapp/WEB-INF/spring/root-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [file:src/main/webapp/WEB-INF/spring/root-context.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.OneToOne.orphanRemoval()Z
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:449)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:120)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:248)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
... 25 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [file:src/main/webapp/WEB-INF/spring/root-context.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.OneToOne.orphanRemoval()Z
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:400)
at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:275)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.detectPersistenceExceptionTranslators(PersistenceExceptionTranslationInterceptor.java:139)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.<init>(PersistenceExceptionTranslationInterceptor.java:79)
at org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisor.<init>(PersistenceExceptionTranslationAdvisor.java:70)
at org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor.setBeanFactory(PersistenceExceptionTranslationPostProcessor.java:103)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1475)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1443)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
... 38 more
Caused by: java.lang.NoSuchMethodError: javax.persistence.OneToOne.orphanRemoval()Z
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1569)
at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:769)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:733)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:636)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:359)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1206)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 53 more
my code:
#RunWith(SpringJUnit4ClassRunner.class)
//#ContextConfiguration(locations="classpath:spring-test.xml")
//#ContextConfiguration(locations="/src/main/webapp/WEB-INF/spring/root-context.xml")
#ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/spring/root-context.xml"})
//#ContextConfiguration(locations="/src/test/resources/spring-test.xml")
public class UserDaoTest {
#Autowired
private UserDao userDao;
#Test
public void firstTest()
{
//long id = userDao.hashCode();
// MilliTimeItem retr = userDAO.getMilliTimeItem(id);
//assertNotNull(retr);
//assertEquals(id,retr.getID());
System.out.println("test");
}
}
I've seen a few similar topics, but I can't fix it. I think that some part of ApplicationContext is load correctly because I see:
NFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from URL [file:src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml]
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
INFO : org.springframework.context.support.GenericApplicationContext - Refreshing org.springframework.context.support.GenericApplicationContext#1cec6b00: startup date [Fri Jan 03 14:06:23 CET 2014]; root of context hierarchy
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO : org.springframework.context.support.GenericApplicationContext - Bean 'dataSource' of type [class org.apache.commons.dbcp.BasicDataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO : org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.5.6-Final
INFO : org.hibernate.cfg.Environment - Hibernate 3.5.6-Final
If I give wrong path to ApplicationContext I will not see messages such as above (only error "Failed to load ApplicationContext"). It is my first encounter with testing. How can I fix it ?
edit1:
Hist_Wyszuk is a simple entity.
Code:
#Entity
#Table(name="Hist_Wyszuk")
public class Hist_Wyszuk
{
#Id
#GeneratedValue
#Column(name="Id")
private Integer id;
#Column(name="Data")
#NotNull
private Date data;
#OneToOne
#JoinColumn(name="IdKat")
private Kategoria kategoria;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Date getData() {
return data;
}
public void setData(Date data) {
this.data = data;
}
public Kategoria getKategoria() {
return kategoria;
}
public void setKategoria(Kategoria kategoria) {
this.kategoria = kategoria;
}
}
edit2:
part of my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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.cebul</groupId>
<name>portalSpol</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
<java-version>1.6</java-version>
<org.springframework-version>3.1.1.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.6.6</org.slf4j-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>spring-binding</artifactId>
<version>2.3.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>spring-js</artifactId>
<version>2.3.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc-portlet</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<!-- uploadPlikow-->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<!-- cglib-->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm-commons</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<!-- Inne do Spring security -->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
</dependency>
<!-- Hibernate Validator -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.5.6-Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
</dependency>
<!-- Jackson JSON Mapper -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.10</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>
<!-- #Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.test.int1.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<artifactId>jez</artifactId>
</project>
Project with this dependencies run correctly. Probelm occurs only in testing