I have a spring-boot project and I'm using spring data rest with it. My build.gradle file looks like this. As you can see I did everything by the manual (well, apparently not everything).
What I want is to have /profile link and ability to get json-schema for all endpoints that I'm publishing. Instead I have /apls link. So I've checked spring-data-rest manual for <2.4 version and it doesn't mention neither /profile link nor json-schema. So I've figured that I'm not using the latest version of spring-data-rest.
I've added spring boot gradle plugin and I'm not specifying version for spring-boot-data-rest dependency. I've also tried to add org.springframework.data:spring-data-rest-webmvc:2.4.0.RELEASE dependency.
But that apparently doesn't work, because I still have /alps link instead of /profile link.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'settings'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
dependencies {
compile group: 'org.zeromq', name: 'jeromq', version: '0.3.5'
compile group: 'org.json', name: 'json', version: '20141113'
compile group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
compile group: 'org.skyscreamer', name: 'jsonassert', version: '1.2.3'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-rest'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-hateoas'
compile group: 'postgresql', name: 'postgresql', version:'9.1-901-1.jdbc4'
compile("org.springframework.data:spring-data-rest-webmvc:2.4.0.RELEASE")
runtime group: 'com.h2database', name: 'h2', version:'1.4.187'
testCompile(group: 'org.springframework.boot', name: 'spring-boot-starter-test') {
exclude(module: 'commons-logging')
}
}
EDIT1:
I've found that if I'm not including dependency
compile("org.springframework.data:spring-data-rest-webmvc:2.4.0.RELEASE")
Than gradle using spring-data-rest 2.2.3 or something like that.
But when I'm including that dependency it uses 2.4.0 like it should be, but then my test is failing for some reason.
My test looks like that
package demo;
import demo.settings.DemoApplication;
import demo.settings.processing.Channel;
import demo.settings.processing.ChannelMode;
import demo.settings.processing.ChannelsController;
import demo.settings.processing.ChannelRepository;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import java.util.List;
import static org.junit.Assert.*;
#RunWith(SpringJUnit4ClassRunner.class)
#SpringApplicationConfiguration(classes = DemoApplication.class)
public class DemoApplicationTests {
final String BASE_URL = "http://localhost:8080/";
private MockMvc mockMvc;
#Autowired
private ChannelsController controller;
#Autowired
private ChannelRepository repository;
#Before
public void setup() {
this.mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
}
#Test
public void setChannels() {
Channel exampleChannel = new Channel(ChannelMode.AUTO, 1, 1, 1, false, 0);
controller.setChannels(0, 10, exampleChannel);
List<Channel> allChannels = repository.findAllByOrderByBinIndexAsc();
for (int i = 0; i <= 10; i++) {
Channel ch = allChannels.get(i);
assertEquals(ch.getBinIndex(), i);
assertEquals(ch.getC1(), exampleChannel.getC1(), 0);
assertEquals(ch.getC2(), exampleChannel.getC2(), 0);
assertEquals(ch.getManualCoefficient(), exampleChannel.getManualCoefficient(), 0);
assertEquals(ch.getMode().toString(), exampleChannel.getMode().toString());
assertEquals(ch.isExcluded(), exampleChannel.isExcluded());
}
exampleChannel.setC1(100);
controller.setChannels(0, 11, exampleChannel);
allChannels = repository.findAllByOrderByBinIndexAsc();
for (int i = 0; i <= 11; i++) {
Channel ch = allChannels.get(i);
assertEquals(ch.getBinIndex(), i);
assertEquals(ch.getC1(), exampleChannel.getC1(), 0);
assertEquals(ch.getC2(), exampleChannel.getC2(), 0);
assertEquals(ch.getManualCoefficient(), exampleChannel.getManualCoefficient(), 0);
assertEquals(ch.getMode().toString(), exampleChannel.getMode().toString());
assertEquals(ch.isExcluded(), exampleChannel.isExcluded());
}
}
}
Here is my repository
#RepositoryRestResource(path="dts_stm32_settings")
interface DtsStm32SettingsRepository extends PagingAndSortingRepository<DtsStm32Settings, Long> {
}
Here is my Model
package demo.settings.data_collection.stm;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
/**
* Created by michael on 11/09/15.
*/
#Entity
public class DtsStm32Settings extends Stm32Settings {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private long id;
#NotNull #Min(value=0) #Max(value=65535)
private int firstChannelDac;
#NotNull #Min(value=0) #Max(value=65535)
private int secondChannelDac;
#NotNull #Min(value=0) #Max(value=65535)
private int dil;
#NotNull
private CommutatorChannel commutatorChannel;
#NotNull #Min(value=0) #Max(value=65535)
private int firstChannelPwm;
#NotNull #Min(value=0) #Max(value=65535)
private int zeroChannelPwm;
public DtsStm32Settings() {
}
public DtsStm32Settings(
int firstChannelShift,
int secondChannelShift,
int firstChannelGain,
int secondChannelGain,
int firstChannelSlope,
int secondChannelSlope,
boolean led,
boolean firstChannelDurationBit,
boolean secondChannelDurationBit,
int firstChannelDac,
int secondChannelDac,
int dil,
CommutatorChannel commutatorChannel,
int firstChannelPwm,
int zeroChannelPwm,
boolean pulsedPumpMode,
int durationOn,
int durationOff
) {
super(firstChannelShift, secondChannelShift, firstChannelGain, secondChannelGain, firstChannelSlope, secondChannelSlope, led, firstChannelDurationBit, secondChannelDurationBit);
this.firstChannelDac = firstChannelDac;
this.secondChannelDac = secondChannelDac;
this.dil = dil;
this.commutatorChannel = commutatorChannel;
this.firstChannelPwm = firstChannelPwm;
this.zeroChannelPwm = zeroChannelPwm;
this.pulsedPumpMode = pulsedPumpMode;
this.durationOn = durationOn;
this.durationOff = durationOff;
}
#NotNull
private boolean pulsedPumpMode;
#NotNull #Min(value=1) #Max(value=65535)
private int durationOn;
#NotNull #Min(value=0) #Max(value=65535)
private int durationOff;
public int getFirstChannelPwm() {
return firstChannelPwm;
}
public void setFirstChannelPwm(int firstChannelPwm) {
this.firstChannelPwm = firstChannelPwm;
}
public int getZeroChannelPwm() {
return zeroChannelPwm;
}
public void setZeroChannelPwm(int zeroChannelPwm) {
this.zeroChannelPwm = zeroChannelPwm;
}
public int getFirstChannelDac() {
return firstChannelDac;
}
public void setFirstChannelDac(int firstChannelDac) {
this.firstChannelDac = firstChannelDac;
}
public int getSecondChannelDac() {
return secondChannelDac;
}
public void setSecondChannelDac(int secondChannelDac) {
this.secondChannelDac = secondChannelDac;
}
public int getDil() {
return dil;
}
public void setDil(int dil) {
this.dil = dil;
}
public CommutatorChannel getCommutatorChannel() {
return commutatorChannel;
}
public void setCommutatorChannel(CommutatorChannel commutatorChannel) {
this.commutatorChannel = commutatorChannel;
}
public boolean isPulsedPumpMode() {
return pulsedPumpMode;
}
public void setPulsedPumpMode(boolean pulsedPumpMode) {
this.pulsedPumpMode = pulsedPumpMode;
}
public int getDurationOn() {
return durationOn;
}
public void setDurationOn(int durationOn) {
this.durationOn = durationOn;
}
public int getDurationOff() {
return durationOff;
}
public void setDurationOff(int durationOff) {
this.durationOff = durationOff;
}
}
package demo.settings.data_collection.stm;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
/**
* Created by michael on 11/09/15.
*/
#JsonTypeInfo(use = JsonTypeInfo.Id.MINIMAL_CLASS, include=JsonTypeInfo.As.PROPERTY, property = "type")
#JsonSubTypes({#JsonSubTypes.Type(DtsStm32Settings.class)})
abstract class Stm32Settings {
#NotNull
#Min(value=0) #Max(value=65535)
protected int firstChannelShift;
#NotNull
#Min(value=0) #Max(value=65535)
protected int secondChannelShift;
#NotNull
#Min(value=0) #Max(value=65535)
protected int firstChannelGain;
#NotNull
#Min(value=0) #Max(value=65535)
protected int secondChannelGain;
#NotNull
#Min(value=0) #Max(value=65535)
protected int firstChannelSlope;
#NotNull
#Min(value=0) #Max(value=65535)
protected int secondChannelSlope;
#NotNull
protected boolean led;
#NotNull
protected boolean firstChannelDurationBit;
#NotNull
protected boolean secondChannelDurationBit;
protected Stm32Settings() {
}
public int getFirstChannelShift() {
return firstChannelShift;
}
public void setFirstChannelShift(int firstChannelShift) {
this.firstChannelShift = firstChannelShift;
}
public int getSecondChannelShift() {
return secondChannelShift;
}
public void setSecondChannelShift(int secondChannelShift) {
this.secondChannelShift = secondChannelShift;
}
public int getFirstChannelGain() {
return firstChannelGain;
}
public void setFirstChannelGain(int firstChannelGain) {
this.firstChannelGain = firstChannelGain;
}
public int getSecondChannelGain() {
return secondChannelGain;
}
public void setSecondChannelGain(int secondChannelGain) {
this.secondChannelGain = secondChannelGain;
}
public int getFirstChannelSlope() {
return firstChannelSlope;
}
public void setFirstChannelSlope(int firstChannelSlope) {
this.firstChannelSlope = firstChannelSlope;
}
public int getSecondChannelSlope() {
return secondChannelSlope;
}
public void setSecondChannelSlope(int secondChannelSlope) {
this.secondChannelSlope = secondChannelSlope;
}
public boolean isLed() {
return led;
}
public void setLed(boolean led) {
this.led = led;
}
public boolean isFirstChannelDurationBit() {
return firstChannelDurationBit;
}
public void setFirstChannelDurationBit(boolean firstChannelDurationBit) {
this.firstChannelDurationBit = firstChannelDurationBit;
}
public boolean isSecondChannelDurationBit() {
return secondChannelDurationBit;
}
public void setSecondChannelDurationBit(boolean secondChannelDurationBit) {
this.secondChannelDurationBit = secondChannelDurationBit;
}
public Stm32Settings(
int firstChannelShift,
int secondChannelShift,
int firstChannelGain,
int secondChannelGain,
int firstChannelSlope,
int secondChannelSlope,
boolean led,
boolean firstChannelDurationBit,
boolean secondChannelDurationBit
) {
setFirstChannelShift(firstChannelShift);
setSecondChannelShift(secondChannelShift);
setFirstChannelGain(firstChannelGain);
setSecondChannelGain(secondChannelGain);
setFirstChannelSlope(firstChannelSlope);
setSecondChannelSlope(secondChannelSlope);
setLed(led);
setFirstChannelDurationBit(firstChannelDurationBit);
setSecondChannelDurationBit(secondChannelDurationBit);
}
}
And here is error which tells me about nothing
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stm32Controller': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private demo.settings.data_collection.stm.DtsStm32SettingsRepository demo.settings.data_collection.stm.Stm32Controller.repository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dtsStm32SettingsRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:687)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
at org.springframework.boot.test.SpringApplicationContextLoader.loadContext(SpringApplicationContextLoader.java:104)
at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:68)
at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:86)
... 45 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private demo.settings.data_collection.stm.DtsStm32SettingsRepository demo.settings.data_collection.stm.Stm32Controller.repository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dtsStm32SettingsRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 60 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dtsStm32SettingsRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
... 62 more
Caused by: java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:185)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:237)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
... 72 more
Try specifying Spring Data release train instead:
dependencyManagement {
imports {
...
mavenBom "org.springframework.data:spring-data-releasetrain:Gosling-RELEASE"
}
}
Then just compile the spring-data starters you need without specifying the version!
Related
I try to throw a DuplicateKeyException in a jUnit 5 Test. The unit test saves two objects to a repository with the same productId. productID is declared #Indexed( unique = true ) in the ProductEntity class. My expectation was to receive a DuplicateKeyException.
This is the test class:
package com.exercim.microservices.core.product;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.exercim.microservices.core.product.persistence.ProductEntity;
import com.exercim.microservices.core.product.persistence.ProductRepository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
import org.springframework.dao.DuplicateKeyException;
#DataMongoTest
public class ProductRepositoryTest {
#Autowired
ProductRepository repository ;
#Test
public void testDuplicateKeyException() {
ProductEntity e1 = new ProductEntity( 1, "name", 1 ) ;
ProductEntity e2 = new ProductEntity( 1, "name", 1 ) ;
repository.deleteAll() ;
repository.save( e1 ) ;
assertThrows(DuplicateKeyException.class, () -> repository.save( e2 ) ) ;
}
}
This is the ProductEntitiy class:
package com.exercim.microservices.core.product.persistence;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
#Document( collection = "products" )
public class ProductEntity {
#Id
private String id ;
#Version
private Integer version ;
#Indexed( unique = true )
private int productId ;
private String name ;
private Integer weight ;
public ProductEntity() {
}
public ProductEntity( int productId, String name, int weight) {
this.productId = productId;
this.name = name;
this.weight = weight;
}
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
public int getVersion() {
return this.version;
}
public void setVersion(int version) {
this.version = version;
}
public int getProductId() {
return this.productId;
}
public void setProductId(int productId) {
this.productId = productId;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public int getWeight() {
return this.weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
}
The repository is an interface which extends PagingAndSortingRepository
This is part of my build.gradle file:
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-mongodb'
testImplementation 'de.flapdoodle.embed:de.flapdoodle.embed.mongo'
The test fails with the message:
org.opentest4j.AssertionFailedError: Expected org.springframework.dao.DuplicateKeyException to be thrown, but nothing was thrown.
at org.junit.jupiter.api.AssertThrows.assertThrows(AssertThrows.java:71)
Does anyone have an idea? Thanks in advance!
Thanks Joe!
The problem was, that auto index creation was not enabled. This was my original application.yml file:
spring.data.mongodb:
host: localhost
port: 27017
database: product-db
I added the following line:
auto-index-creation: true
That solved the issue.
I am developing the backend part of a registration page for my website, the problem is that when I test this in postman I get the following error:
and I also get this error in my eclipse console:
2020-05-29 17:58:06.226 ERROR 1368 --- [nio-8484-exec-8] o.h.engine.jdbc.spi.SqlExceptionHelper : ORA-01400: impossible d'insérer NULL dans ("NAWFEL"."ORDO_DEP_UTILISATEUR"."IDENTIFIANT")
2020-05-29 17:58:06.230 ERROR 1368 --- [nio-8484-exec-8] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement] with root cause
oracle.jdbc.OracleDatabaseException: ORA-01400: impossible d'insérer NULL dans ("NAWFEL"."ORDO_DEP_UTILISATEUR"."IDENTIFIANT")
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:513) ~[ojdbc8-19.3.0.0.jar:19.3.0.0.0]
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:461) ~[ojdbc8-19.3.0.0.jar:19.3.0.0.0]
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1104) ~[ojdbc8-19.3.0.0.jar:19.3.0.0.0]
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:550) ~[ojdbc8-19.3.0.0.jar:19.3.0.0.0]
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:268) ~[ojdbc8-19.3.0.0.jar:19.3.0.0.0]
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:655) ~[ojdbc8-19.3.0.0.jar:19.3.0.0.0]
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:270) ~[ojdbc8-19.3.0.0.jar:19.3.0.0.0]
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:91) ~[ojdbc8-19.3.0.0.jar:19.3.0.0.0]
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:970) ~[ojdbc8-19.3.0.0.jar:19.3.0.0.0]
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1205) ~[ojdbc8-19.3.0.0.jar:19.3.0.0.0]
I see that the error comes from the id but as you can see here I inserted the id in postman in the json part :
{
"id":2,
"EMPLOI":2,
"ENTITE":2,
"LOGIN":"hr",
"MOTDEPASSE":"hr",
"NOM":"bougrine",
"PRENOM":"rachid",
"STATUT":"br",
"CREEPAR": 2
}
this is my code for configure spring security in my app :
package com.app.habilitation.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
#Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
#Override
protected void configure (HttpSecurity http) throws Exception {
http.cors();
http.csrf().disable();
http.authorizeRequests().antMatchers("/**").
fullyAuthenticated().and().httpBasic();
}
#Override
protected void configure (AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("hr")
.password("{noop}hr").roles("USER");
}
}
and this is my controller :
package com.app.habilitation.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.app.habilitation.entity.UserEntity;
import com.app.habilitation.service.UserService;
#SpringBootApplication
#RestController
#CrossOrigin(origins = "*")
public class UserController {
private UserService userService;
#Autowired
public UserController (UserService theuserService) {
userService=theuserService;
}
#GetMapping("/")
public String login() {
return "authenticaated succesfully";
}
#GetMapping("/getUsers")
public String getUsers() {
return "users";
}
#PostMapping("/addUser")
public UserEntity addUser (#RequestBody UserEntity theUser) {
System.out.println("test");
userService.save(theUser);
return theUser;
}
}
and this is my dao ( i use jpa) :
package com.app.habilitation.dao;
import org.springframework.data.jpa.repository.JpaRepository;
import com.app.habilitation.entity.UserEntity;
public interface UserDao extends JpaRepository<UserEntity, Integer> {
}
this is my entity class :
package com.app.habilitation.entity;
import java.sql.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
#Entity
#Table(name="ORDO_DEP_UTILISATEUR")
public class UserEntity {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name="IDENTIFIANT")
private Integer IDENTIFIANT;
/*#ManyToOne(cascade = {CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
#JoinColumn(name="EMPLOI") */
#Column(name="EMPLOI")
private Integer emploi;
/* #ManyToOne(cascade = {CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
#JoinColumn(name="ENTITE") */
#Column(name="ENTITE")
private Integer entite;
#Column(name="LOGIN")
private String login;
#Column(name="MOTDEPASSE")
private String mdp;
#Column(name="nom")
private String nom;
#Column(name="prenom")
private String prenom;
#Column(name="CREEPAR")
private Integer creerpar;
#Column(name="ANNULEPAR")
private Integer annulepar;
#Column(name="STATUT")
private String statut;
#Column(name="DATEEFFET")
private Date dateeffet;
#Column(name="DATEFIN")
private Date datefin;
#Column(name="CREELE")
private Date creele;
#Column(name="MOTIFDEDESACTIVATION")
private String motifdedesactivation;
#Column(name="ANNULELE")
private Date annulele;
public Integer getIDENTIFIANT() {
return IDENTIFIANT;
}
public void setIDENTIFIANT(Integer iDENTIFIANT) {
IDENTIFIANT = iDENTIFIANT;
}
public Integer getEmploi() {
return emploi;
}
public void setEmploi(Integer emploi) {
this.emploi = emploi;
}
public Integer getEntite() {
return entite;
}
public void setEntite(Integer entite) {
this.entite = entite;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getMdp() {
return mdp;
}
public void setMdp(String mdp) {
this.mdp = mdp;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
public Integer getCreerpar() {
return creerpar;
}
public void setCreerpar(Integer creerpar) {
this.creerpar = creerpar;
}
public Integer getAnnulepar() {
return annulepar;
}
public void setAnnulepar(Integer annulepar) {
this.annulepar = annulepar;
}
public String getStatut() {
return statut;
}
public void setStatut(String statut) {
this.statut = statut;
}
public Date getDateeffet() {
return dateeffet;
}
public void setDateeffet(Date dateeffet) {
this.dateeffet = dateeffet;
}
public Date getDatefin() {
return datefin;
}
public void setDatefin(Date datefin) {
this.datefin = datefin;
}
public Date getCreele() {
return creele;
}
public void setCreele(Date creele) {
this.creele = creele;
}
public String getMotifdedesactivation() {
return motifdedesactivation;
}
public void setMotifdedesactivation(String motifdedesactivation) {
this.motifdedesactivation = motifdedesactivation;
}
public Date getAnnulele() {
return annulele;
}
public void setAnnulele(Date annulele) {
this.annulele = annulele;
}
public UserEntity(Integer iDENTIFIANT, Integer emploi, Integer entite, String login, String mdp, String nom,
String prenom, Integer creerpar, Integer annulepar, String statut, Date dateeffet, Date datefin,
Date creele, String motifdedesactivation, Date annulele) {
IDENTIFIANT = iDENTIFIANT;
this.emploi = emploi;
this.entite = entite;
this.login = login;
this.mdp = mdp;
this.nom = nom;
this.prenom = prenom;
this.creerpar = creerpar;
this.annulepar = annulepar;
this.statut = statut;
this.dateeffet = dateeffet;
this.datefin = datefin;
this.creele = creele;
this.motifdedesactivation = motifdedesactivation;
this.annulele = annulele;
}
public UserEntity() {
}
#Override
public String toString() {
return "UserEntity [IDENTIFIANT=" + IDENTIFIANT + ", emploi=" + emploi + ", entite=" + entite + ", login="
+ login + ", mdp=" + mdp + ", nom=" + nom + ", prenom=" + prenom + ", creerpar=" + creerpar
+ ", annulepar=" + annulepar + ", statut=" + statut + ", dateeffet=" + dateeffet + ", datefin="
+ datefin + ", creele=" + creele + ", motifdedesactivation=" + motifdedesactivation + ", annulele="
+ annulele + "]";
}
}
this is my service interface :
package com.app.habilitation.service;
import java.util.List;
import com.app.habilitation.entity.UserEntity;
public interface UserService {
public void save (UserEntity theUser);
}
and this is my service interface Impl :
package com.app.habilitation.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.app.habilitation.dao.UserDao;
import com.app.habilitation.entity.UserEntity;
#Service
public class UserServiceImpl implements UserService {
private UserDao userDao;
#Autowired
public UserServiceImpl (UserDao theuserDao) {
userDao = theuserDao;
}
#Override
#Transactional
public void save(UserEntity theUser) {
userDao.save(theUser);
}
}
this is my application.properties ( i change port 8080 to 8484 because a nother application use this port) :
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:#localhost:1521:XE
spring.datasource.username=nawfel
spring.datasource.password=hr
spring.jpa.show-sql=true
server.port=8484
and this is my table in oracle 10g :
I think the problem is that you are telling in your entity that id is a generated value. Doing so the value is removed by Jpa during insert. You have to change your strategy, if you are supplying the id you should not mark it as autogenerated.
hth
http://spring.io/guides/gs/accessing-data-jpa/
Referred the above link to define a custom query.
We have a developed a Spring boot web service CRUD application but we are facing the following exception when we add a custom query.
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'EmployeeController': Unsatisfied dependency expressed through field 'EmployeeService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'EmployeeServiceImpl': Unsatisfied dependency expressed through field 'EmployeeRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'EmployeeRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property name found for type Employee!
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'EmployeeServiceImpl': Unsatisfied dependency expressed through field 'EmployeeRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'EmployeeRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property name found for type Employee!
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'EmployeeRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property name found for type Employee!
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property name found for type Employee!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:77) ~[spring-data-commons-1.13.4.RELEASE.jar:naat org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
This was the repository interface that I have defined. Defined a custom query.
package com.example.rest.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.example.rest.model.Employee;
#Repository
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
Employee findByName(String employeeName);}
This is my service interface
package com.example.rest.service;
import java.util.List;
import com.example.rest.model.Employee;
public interface EmployeeService {
Employee save(Employee employee);
Employee getById(Long employeeId);
void delete(Long employeeId);
List<Employee> findAll();
Employee findByName(String employeeName); }
This is my Service Implementation class
package com.example.rest.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.rest.model.Employee;
import com.example.rest.repository.EmployeeRepository;
#Service
public class EmployeeServiceImpl implements EmployeeService {
#Autowired
EmployeeRepository employeeRepository;
#Override
public Employee save(Employee employee) {
// TODO Auto-generated method stub
return employeeRepository.save(employee);
}
#Override
public Employee getById(Long employeeId) {
// TODO Auto-generated method stub
return employeeRepository.getOne(employeeId);
}
#Override
public void delete(Long employeeId) {
// TODO Auto-generated method stub
employeeRepository.delete(employeeId);
}
#Override
public List<Employee> findAll() {
// TODO Auto-generated method stub
return employeeRepository.findAll();
}
#Override
public Employee findByName(String employeeName) {
// TODO Auto-generated method stub
return employeeRepository.findByName(employeeName);
}}
Without custom query my application works fine.
Let me know where I have made a mistake.
I have added the model class
package com.example.rest.model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name="testF")
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Column(nullable=false, unique=true)
private Long employeeId;
#Column(nullable=false, unique=true)
private String employeeName;
#Column(nullable=false)
private String emailId;
#Column(nullable=false)
private Long salary;
public Employee() {
}
public Employee(Long employeeId, String employeeName, String emailId, Long salary) {
this.employeeId = employeeId;
this.employeeName = employeeName;
this.emailId = emailId;
this.salary = salary;
}
public Long getEmployeeId() {
return employeeId;
}
public void setEmployeeId(Long employeeId) {
this.employeeId = employeeId;
}
public String getEmployeeName() {
return employeeName;
}
public void setEmployeeName(String employeeName) {
this.employeeName = employeeName;
}
public String getEmailId() {
return emailId;
}
public void setEmailId(String emailId) {
this.emailId = emailId;
}
public Long getSalary() {
return salary;
}
public void setSalary(Long salary) {
this.salary = salary;
}
#Override
public String toString() {
return "Employee [employeeId=" + employeeId + ", employeeName=" + employeeName + ", emailId=" + emailId
+ ", salary=" + salary + "]";
}
#Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((employeeId == null) ? 0 : employeeId.hashCode());
return result;
}
#Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Employee other = (Employee) obj;
if (employeeId == null) {
if (other.employeeId != null)
return false;
} else if (!employeeId.equals(other.employeeId))
return false;
return true;
}}
you don't have field 'name' in class Employee.
spring data try created query for search Employee with field name.
Employee findByName(String employeeName);}
Your model doesn't have name property, you have employeeName, so your query should look like this:
Employee findByEmployeeName(String employeeName);
Please see reference for more info on how to build Spring Data queries. In short, when you want to create a query you have to specify full field name how it is written in your Entity.
u can't write findByName in your custom query because u don't have a name field however u can write EmployeeName
I just moved from mongo 2.0.6 do 3.2 and noticed that the unique-index is now used for nested objects too.
Is there a way to tell mongo to prevent unique-index for nested objects?
I declare the index for the nested-object like #Indexed(unique = true)
Spring version: 4.2.5.RELEASE
Spring-data-mongodb version: 1.8.4.RELEASE
Mongo-driver version: mongo-java-driver 3.2.2
My Code:
package jobs;
import org.springframework.data.mongodb.core.mapping.Document;
#Document(collection = "jobs")
public class Job {
private String title;
private CityInfo cityInfo;
// getter/setter
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public CityInfo getCityInfo() {
return cityInfo;
}
public void setCityInfo(CityInfo cityInfo) {
this.cityInfo = cityInfo;
}
}
package jobs;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
#Document(collection = "city_infos")
public class CityInfo {
#Indexed(unique = true)
private String cityName;
// getter/setter
public String getCityName() {
return cityName;
}
public void setCityName(String cityName) {
this.cityName = cityName;
}
}
package jobs;
import org.springframework.data.mongodb.core.MongoOperations;
public class JobMain {
public static void main(String[] args) {
MongoOperations mongo = MongoPoolingUtils.getCentralTemplate();
CityInfo cityInfo = new CityInfo();
cityInfo.setCityName("Berlin");
Job job1 = new Job();
job1.setTitle("java coder");
job1.setCityInfo(cityInfo);
Job job2 = new Job();
job2.setTitle("php coder");
job2.setCityInfo(cityInfo);
mongo.save(job1);
mongo.save(job2);
}
}
Only 1 job is saved to the database.
We are in the process of upgrading all our third-party libraries to the latest versions, mostly related to Spring 4 and Hibernate 4. After fixing all the compilation issues, I am running into a deployment issue in Jboss 4.2.3. When I debugged into the Hibernate code I figured out where the exception is. But not sure why this causes a NPE.
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheService' defined in class path resource [dataSource.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [dataSource.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
... 152 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [dataSource.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
... 162 more
Caused by: java.lang.NullPointerException
at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:550)
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:258)
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:116)
at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1596)
at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1519)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1420)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:343)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:431)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:416)
at com.om.dh.util.EnhancedAnnotationSessionFactoryBean.afterPropertiesSet(EnhancedAnnotationSessionFactoryBean.java:185)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
... 169 more
Exception is happening when referencedEntity.getKey() returning null for the below object in org.hibernate.cfg.Ejb3JoinColumn.java. This was working with Hibernate 3.3.0 and Spring 3.2.2
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
#Entity
#Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
#Table(name = "lk_mc_instrument_type")
public class MCInstrumentType {
#Id
#OneToOne(mappedBy = "instrumentType" )
#JoinColumn(name="mc_instrument_type_code" )
private String code;
private String description;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String toString(){
return description;
}
}
Above class is referred from the below domain object.
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Version;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import com.domainlanguage.time.CalendarDate;
import com.om.dh.domain.AuditInfo;
import com.om.dh.util.idgenerator.DatabaseIdGenerator;
#Entity
#Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
#Table(name = "mc_early_close_instrument")
#GenericGenerator(name="EarlyCloseInstrument_gen",strategy="com.om.dh.util.idgenerator.DatabaseIdGenerator",
parameters={#Parameter(name=DatabaseIdGenerator.INITIAL_PARAM,value="1"),
#Parameter(name = DatabaseIdGenerator.INCREMENT_PARAM, value = "50")})
public class EarlyCloseInstrument {
#Id
#Column(name="EARLY_CLOSE_INST_ID")
#GeneratedValue(generator="EarlyCloseInstrument_gen")
private Long earlycloseInstrumentId;
#OneToOne()
#JoinColumn (name = "INSTRUMENT_TYPE_CODE", referencedColumnName = "mc_instrument_type_code", updatable = false, insertable = false)
private MCInstrumentType instrumentType;
#Column(name="DATE")
#Type(type = "com.om.dh.util.CalendarUserType")
private CalendarDate date;
#Column(name="END_TIME")
private Date time;
#Embedded
private AuditInfo auditInfo;
#Version
#Column(name="VERSION_NUMBER")
private Integer versionNumber;
#Column(name="END_TIMEZONE")
private String endTimezone;
public String getEndTimezone() {
return endTimezone;
}
public void setEndTimezone(String endTimezone) {
this.endTimezone = endTimezone;
}
public AuditInfo getAuditInfo() {
return auditInfo;
}
public void setAuditInfo(AuditInfo auditInfo) {
this.auditInfo = auditInfo;
}
public Integer getVersionNumber() {
return versionNumber;
}
public void setVersionNumber(Integer versionNumber) {
this.versionNumber = versionNumber;
}
public CalendarDate getDate() {
return date;
}
public void setDate(CalendarDate date) {
this.date = date;
}
public Long getEarlycloseInstrumentId() {
return earlycloseInstrumentId;
}
public void setEarlycloseInstrumentId(Long earlycloseInstrumentId) {
this.earlycloseInstrumentId = earlycloseInstrumentId;
}
public MCInstrumentType getInstrumentType() {
return instrumentType;
}
public void setInstrumentType(MCInstrumentType instrumentType) {
this.instrumentType = instrumentType;
}
public Date getTime() {
return time;
}
public void setTime(Date time) {
this.time = time;
}
}
I have listed the jars present in WEB-INF/lib folder under the war file.
activation-1.1.jar
activemq-core-5.7.0.jar
activemq-pool-5.7.0.jar
activemq-protobuf-1.1.jar
ant-1.5.jar
antlr-2.7.7.jar
aopalliance-1.0.jar
apache-mime4j-core-0.7.2.jar
appia-6.1.8.1.jar
asm-3.3.1.jar
asm-commons-3.3.1.jar
asm-tree-3.3.1.jar
aspectjrt-1.7.4.jar
aspectjweaver-1.7.4.jar
avalon-framework-api-4.3.1.jar
avalon-framework-impl-4.3.1.jar
axiom-api-1.2.14.jar
axiom-impl-1.2.14.jar
axis2-1.3.jar
axis-c8-1.0.jar
backport-util-concurrent-3.1.jar
batch-core-7.0-SNAPSHOT.jar
batik-awt-util-1.6-1.jar
batik-bridge-1.6-1.jar
batik-css-1.6-1.jar
batik-dom-1.6-1.jar
batik-ext-1.6-1.jar
batik-extension-1.6-1.jar
batik-gui-util-1.6-1.jar
batik-gvt-1.6-1.jar
batik-parser-1.6-1.jar
batik-script-1.6-1.jar
batik-svg-dom-1.6-1.jar
batik-transcoder-1.6-1.jar
batik-util-1.6-1.jar
batik-xml-1.6-1.jar
bcmail-jdk14-138.jar
bcprov-jdk14-138.jar
blazeds-common-3.2.0.3978.jar
blazeds-core-3.2.0.3978.jar
blazeds-proxy-3.2.0.3978.jar
blazeds-remoting-3.2.0.3978.jar
Cairngorm.swc
castor-1.1.2.1.jar
cglib-nodep-2.1_3.jar
com.ibm.jbatch-tck-spi-1.0.jar
commons-beanutils-1.7.0.jar
commons-codec-1.3.jar
commons-collections-3.2.jar
commons-dbcp-1.2.2.jar
commons-digester-1.8.jar
commons-discovery-0.4.jar
commons-fileupload-1.1.1.jar
commons-httpclient-3.0.1.jar
commons-io-1.4.jar
commons-jexl-1.1.jar
commons-lang-2.4.jar
commons-lang3-3.1.jar
commons-logging-1.1.1.jar
commons-logging-api-1.1.jar
commons-math-1.1.jar
commons-net-1.4.1.jar
commons-pool-1.6.jar
commons-vfs-1.0.jar
corelib.swc
custompopupmanager.swc
cxf-api-2.7.9.jar
cxf-rt-bindings-soap-2.7.9.jar
cxf-rt-bindings-xml-2.7.9.jar
cxf-rt-core-2.7.9.jar
cxf-rt-databinding-jaxb-2.7.9.jar
cxf-rt-frontend-jaxws-2.7.9.jar
cxf-rt-frontend-simple-2.7.9.jar
cxf-rt-transports-http-2.7.9.jar
cxf-rt-ws-addr-2.7.9.jar
cxf-rt-ws-policy-2.7.9.jar
dom4j-1.6.1.jar
domain-7.0-SNAPSHOT.jar
encoder-1.1.1.jar
extra166y-1.0.jar
FastInfoset-1.2.12.jar
fix-4.4-appia-6.1.8.1.jar
flexhttpplugin.swc
flexjsonplugin.swc
fontbox-1.8.4.jar
fop-0.94.jar
freemarker-2.3.19.jar
geronimo-j2ee-management_1.0_spec-1.1.jar
geronimo-jms_1.1_spec-1.1.1.jar
geronimo-jta_1.0.1B_spec-1.0.1.jar
hawtbuf-1.9.jar
hawtdispatch-1.11.jar
hawtdispatch-transport-1.11.jar
hibernate-commons-annotations-4.0.4.Final.jar
hibernate-core-4.3.2.Final.jar
hibernate-jmx-3.5.6-Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
hibernate-validator-4.3.2.Final.jar
icu4j-4.0.1.jar
istack-commons-runtime-2.16.jar
itext-2.1.4.jar
jackson-core-asl-1.0.0.jar
jandex-1.1.0.Final.jar
janino-2.5.15.jar
jasypt-1.9.2.jar
jasypt-hibernate4-1.9.2.jar
jasypt-spring31-1.9.2.jar
jasypt-springsecurity3-1.9.2.jar
javassist-3.18.1-GA.jar
javax.batch-api-1.0.jar
jaxb-core-2.2.7.jar
jaxb-impl-2.2.7.jar
jaxen-1.1.4.jar
jaxrpc-api-1.1.jar
jboss-logging-3.1.3.GA.jar
jboss-logging-annotations-1.2.0.Beta1.jar
jboss-transaction-api_1.2_spec-1.0.0.Final.jar
jempbox-1.8.4.jar
jettison-1.2.jar
jmxri-1.2.1.jar
jmxtools-1.2.1.jar
joda-time-2.3.jar
js-1.5R4.1.jar
jsch-0.1.38.jar
json.swc
jsr166y-1.0.jar
jxls-core-0.9.5.jar
kahadb-5.7.0.jar
Lightstreamer_as_client.swc
log4j-1.2.15.jar
log4j-extras-1.1.jar
lucene-core-3.6.0.jar
mail-1.4.jar
mina-core-1.1.7.jar
mina-filter-ssl-1.1.7.jar
mina-integration-spring-1.1.7.jar
mqtt-client-1.3.jar
neethi-3.0.3.jar
ognl-3.0.6.jar
opencsv-1.8.jar
openfast-core-1.1.2.jar
oro-2.0.8.jar
pdfbox-1.8.4.jar
poi-3.0.1-FINAL.jar
quartz-1.6.0.jar
quickfixj-core-1.5.3.jar
quickfixj-msg-fix40-1.5.3.jar
quickfixj-msg-fix41-1.5.3.jar
quickfixj-msg-fix42-1.5.3.jar
quickfixj-msg-fix43-1.5.3.jar
quickfixj-msg-fix44-1.5.3.jar
rfa-7.4.0L1.jar
serializer-2.7.1.jar
servlet-api-2.4.jar
simplecaptcha-1.2.1.jar
sitemesh-2.4.2.jar
slf4j-api-1.4.2.jar
slf4j-jcl-1.4.2.jar
slf4j-log4j12-1.4.2.jar
sojo-0.5.0.jar
spring-aop-4.0.6.RELEASE.jar
spring-batch-core-3.0.1.RELEASE.jar
spring-batch-infrastructure-3.0.1.RELEASE.jar
spring-batch-integration-3.0.1.RELEASE.jar
spring-beans-4.0.6.RELEASE.jar
spring-context-4.0.6.RELEASE.jar
spring-context-support-4.0.6.RELEASE.jar
spring-core-4.0.6.RELEASE.jar
spring-expression-4.0.6.RELEASE.jar
spring-flex-1.0.1.RELEASE.jar
spring-integration-core-4.0.3.RELEASE.jar
spring-integration-jms-4.0.3.RELEASE.jar
spring-jdbc-4.0.6.RELEASE.jar
spring-jms-4.0.6.RELEASE.jar
spring-messaging-4.0.6.RELEASE.jar
spring-orm-4.0.6.RELEASE.jar
spring-oxm-1.5.5.jar
spring-retry-1.1.0.RELEASE.jar
spring-security-config-3.2.4.RELEASE.jar
spring-security-core-3.2.4.RELEASE.jar
spring-security-web-3.2.4.RELEASE.jar
spring-test-4.0.6.RELEASE.jar
spring-tx-4.0.6.RELEASE.jar
spring-web-4.0.6.RELEASE.jar
spring-webmvc-4.0.6.RELEASE.jar
spring-webmvc-struts-2.5.6.jar
spring-xml-1.5.5.jar
stax2-api-3.1.1.jar
stax-api-1.0.1.jar
struts2-config-browser-plugin-2.3.16.jar
struts2-core-2.3.15.1.jar
struts2-dojo-plugin-2.3.15.1.jar
struts2-jquery-plugin-3.6.1.jar
struts2-spring-plugin-2.3.15.1.jar
struts2-tiles-plugin-2.3.15.1.jar
strutsjsonplugin-7.0-SNAPSHOT.jar
tiles-api-2.1.3.jar
tiles-core-2.1.3.jar
tiles-jsp-2.1.3.jar
tiles-servlet-2.1.3.jar
twitter4j-core-3.0.jar
urlrewritefilter-3.0.4.jar
validation-api-1.0.0.GA.jar
velocity-1.5.jar
velocity-tools-1.1.jar
woden-1.0-incubating-M7b.jar
woodstox-core-asl-4.2.0.jar
ws-commons-util-1.0.1.jar
wsdl4j-1.6.3.jar
xalan-2.7.1.jar
xercesImpl-2.9.0.jar
xml-apis-1.0.b2.jar
xmlbeans-2.4.0.jar
xmlConverter.swc
xmlgraphics-commons-1.2.jar
xmlParserAPIs-2.0.2.jar
xmlpull-1.1.3.1.jar
xml-resolver-1.2.jar
xmlschema-core-2.1.0.jar
xmlsyndication.swc
xpp3_min-1.1.4c.jar
xstream-1.4.7.jar
xwork-core-2.3.15.1.jar
Please let me know if you need more information.
Thanks in advance,
Ram
Try by removing referencedColumnName from EarlyCloseInstrument
#OneToOne(cascade = CascadeType.ALL)
#JoinColumn (name = "INSTRUMENT_TYPE_CODE", updatable = false, insertable = false)
private MCInstrumentType instrumentType;