NPE in Hibernate 4 - spring

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;

Related

Error while binding parameter from AWS Parameter Store in Spring Boot

Due to some know vulnerabilities, I can't use spring-cloud-starter-aws-parameter-store-config in my org. So I simply tried to extract code from jar and use it in my project. But I'm not able to bind parameter from aws store to spring boot. I'm getting following error-
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'db.username' in value "${db.username}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:178) ~[spring-core-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124) ~[spring-core-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:236) ~[spring-core-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210) ~[spring-core-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:175) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$$Lambda$220/254979217.resolveStringValue(Unknown Source) ~[na:na]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:908) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1228) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:636) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:116) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:397) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
... 37 common frames omitted
These are the files that I'm using
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
#Configuration
#EnableConfigurationProperties({AwsParamStoreProperties.class})
#ConditionalOnClass({AWSSimpleSystemsManagement.class, AwsParamStorePropertySourceLocator.class})
#ConditionalOnProperty(
prefix = "aws.paramstore",
name = {"enabled"},
matchIfMissing = true
)
public class AwsParamStoreBootstrapConfiguration {
}
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
#ConfigurationProperties("aws.paramstore")
#Validated
public class AwsParamStoreProperties {
public static final String CONFIG_PREFIX = "aws.paramstore";
#NotNull
#Pattern(
regexp = "(/[a-zA-Z0-9.\\-_]+)*"
)
private String prefix = "/config";
#NotEmpty
private String defaultContext = "application";
#NotNull
#Pattern(
regexp = "[a-zA-Z0-9.\\-_/]+"
)
private String profileSeparator = "_";
private boolean failFast = true;
private String name;
private boolean enabled = true;
public AwsParamStoreProperties() {
}
//Getter and Setters
}
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
import com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathRequest;
import com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult;
import com.amazonaws.services.simplesystemsmanagement.model.Parameter;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import org.springframework.core.env.EnumerablePropertySource;
public class AwsParamStorePropertySource extends EnumerablePropertySource<AWSSimpleSystemsManagement> {
private String context;
private Map<String, Object> properties = new LinkedHashMap();
public AwsParamStorePropertySource(String context, AWSSimpleSystemsManagement ssmClient) {
super(context, ssmClient);
this.context = context;
}
public void init() {
GetParametersByPathRequest paramsRequest = (new GetParametersByPathRequest()).withPath(this.context).withRecursive(true).withWithDecryption(true);
this.getParameters(paramsRequest);
}
public String[] getPropertyNames() {
Set<String> strings = this.properties.keySet();
return (String[])strings.toArray(new String[strings.size()]);
}
public Object getProperty(String name) {
return this.properties.get(name);
}
private void getParameters(GetParametersByPathRequest paramsRequest) {
GetParametersByPathResult paramsResult = ((AWSSimpleSystemsManagement)this.source).getParametersByPath(paramsRequest);
Iterator var3 = paramsResult.getParameters().iterator();
while(var3.hasNext()) {
Parameter parameter = (Parameter)var3.next();
String key = parameter.getName().replace(this.context, "").replace('/', '.');
this.properties.put(key, parameter.getValue());
}
if (paramsResult.getNextToken() != null) {
this.getParameters(paramsRequest.withNextToken(paramsResult.getNextToken()));
}
}
}
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertySource;
import org.springframework.util.ReflectionUtils;
public class AwsParamStorePropertySourceLocator implements PropertySourceLocator {
private AWSSimpleSystemsManagement ssmClient;
private AwsParamStoreProperties properties;
private List<String> contexts = new ArrayList();
private Log logger = LogFactory.getLog(this.getClass());
public AwsParamStorePropertySourceLocator(AWSSimpleSystemsManagement ssmClient, AwsParamStoreProperties properties) {
this.ssmClient = ssmClient;
this.properties = properties;
}
public List<String> getContexts() {
return this.contexts;
}
public PropertySource<?> locate(Environment environment) {
if (!(environment instanceof ConfigurableEnvironment)) {
return null;
} else {
ConfigurableEnvironment env = (ConfigurableEnvironment)environment;
String appName = this.properties.getName();
if (appName == null) {
appName = env.getProperty("spring.application.name");
}
List<String> profiles = Arrays.asList(env.getActiveProfiles());
String prefix = this.properties.getPrefix();
String defaultContext = prefix + "/" + this.properties.getDefaultContext();
this.contexts.add(defaultContext + "/");
this.addProfiles(this.contexts, defaultContext, profiles);
String baseContext = prefix + "/" + appName;
this.contexts.add(baseContext + "/");
this.addProfiles(this.contexts, baseContext, profiles);
Collections.reverse(this.contexts);
CompositePropertySource composite = new CompositePropertySource("aws-param-store");
Iterator var9 = this.contexts.iterator();
while(var9.hasNext()) {
String propertySourceContext = (String)var9.next();
try {
composite.addPropertySource(this.create(propertySourceContext));
} catch (Exception var12) {
if (this.properties.isFailFast()) {
this.logger.error("Fail fast is set and there was an error reading configuration from AWS Parameter Store:\n" + var12.getMessage());
ReflectionUtils.rethrowRuntimeException(var12);
} else {
this.logger.warn("Unable to load AWS config from " + propertySourceContext, var12);
}
}
}
return composite;
}
}
private AwsParamStorePropertySource create(String context) {
AwsParamStorePropertySource propertySource = new AwsParamStorePropertySource(context, this.ssmClient);
propertySource.init();
return propertySource;
}
private void addProfiles(List<String> contexts, String baseContext, List<String> profiles) {
Iterator var4 = profiles.iterator();
while(var4.hasNext()) {
String profile = (String)var4.next();
contexts.add(baseContext + this.properties.getProfileSeparator() + profile + "/");
}
}
}
bootstrap.yml
aws:
paramstore:
prefix: /config
name: sample
enabled: true
profileSeparator: _
spring.factories
org.springframework.cloud.bootstrap.BootstrapConfiguration=\com.app.paramstore.AwsParamStoreBootstrapConfiguration

Spring Boot JPA repositories custom query

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

spring form validation using custom annotation

I am using custom annotation for form validation in my spring4.2.3 and hibernate5.1.0 based project.
1) My Annotation Interface looks like this
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;
import com.rapidtech.rapidtechorganic.custom.logic.UnitConstraintValidator;
#Documented
#Constraint(validatedBy = UnitConstraintValidator.class)
#Target( {ElementType.FIELD})
#Retention(RetentionPolicy.RUNTIME)
public #interface IsUnit {
String message() default "Please Enter a valid UNIT e.g. kg,litre,ton";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
2) My logic class UnitConstraintValidator looks like this
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import com.rapidtech.rapidtechorganic.custom.annotation.IsUnit;
public class UnitConstraintValidator implements ConstraintValidator<IsUnit, String> {
#Override
public void initialize(IsUnit unit) {
// TODO Auto-generated method stub
}
#Override
public boolean isValid(String unit, ConstraintValidatorContext cxt) {
if(unit.equals(null) || unit == null){
return false;
}
if(unit.matches("kg|KG|Kg|Litre|litre|lt|ton|Ton")){
return true;
}
return false;
}
}
3) My Model class where I am using custom annotation
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.validation.constraints.Size;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.rapidtech.rapidtechorganic.custom.annotation.IsUnit;
#JsonIgnoreProperties(ignoreUnknown = true)
#Entity
public class Lot implements java.io.Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
private long lotId;
#Size(min=5,max=30)
private String lotNumber;
#IsUnit
private String lotName;
#OneToOne(cascade = {CascadeType.ALL})
private ProductAvailable productAvailable;
public long getLotId() {
return lotId;
}
public void setLotId(long lotId) {
this.lotId = lotId;
}
public String getLotNumber() {
return lotNumber;
}
public void setLotNumber(String lotNumber) {
this.lotNumber = lotNumber;
}
public String getLotName() {
return lotName;
}
public void setLotName(String lotName) {
this.lotName = lotName;
}
public ProductAvailable getProductAvailable() {
return productAvailable;
}
public void setProductAvailable(ProductAvailable productAvailable) {
this.productAvailable = productAvailable;
}
}
4) My ProductAvailable model class where I am using custom annotation
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.validation.constraints.Size;
import com.rapidtech.rapidtechorganic.custom.annotation.IsUnit;
#Entity
public class ProductAvailable implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
private long productAvailableId;
#Size(min=2,max=30,message="ahha ahha ahha")
private String productAvailableName;
#IsUnit
private String productAvailableUnit;
private double productAvailableUnitTransportationCharge;
private double productAvailableUnitLabourCharge;
private double productAvailableUnitOtherCharge;
private long productAvailableQuantity;
private double productAvailableUnitPrice;
#OneToOne
private Lot lot;
public long getProductAvailableId() {
return productAvailableId;
}
public void setProductAvailableId(long productAvailableId) {
this.productAvailableId = productAvailableId;
}
public String getProductAvailableName() {
return productAvailableName;
}
public void setProductAvailableName(String productAvailableName) {
this.productAvailableName = productAvailableName;
}
public long getProductAvailableQuantity() {
return productAvailableQuantity;
}
public void setProductAvailableQuantity(long productAvailableQuantity) {
this.productAvailableQuantity = productAvailableQuantity;
}
public double getProductAvailableUnitPrice() {
return productAvailableUnitPrice;
}
public void setProductAvailableUnitPrice(double productAvailableUnitPrice) {
this.productAvailableUnitPrice = productAvailableUnitPrice;
}
public String getProductAvailableUnit() {
return productAvailableUnit;
}
public void setProductAvailableUnit(String productAvailableUnit) {
this.productAvailableUnit = productAvailableUnit;
}
public double getProductAvailableUnitTransportationCharge() {
return productAvailableUnitTransportationCharge;
}
public void setProductAvailableUnitTransportationCharge(double productAvailableUnitTransportationCharge) {
this.productAvailableUnitTransportationCharge = productAvailableUnitTransportationCharge;
}
public double getProductAvailableUnitLabourCharge() {
return productAvailableUnitLabourCharge;
}
public void setProductAvailableUnitLabourCharge(double productAvailableUnitLabourCharge) {
this.productAvailableUnitLabourCharge = productAvailableUnitLabourCharge;
}
public double getProductAvailableUnitOtherCharge() {
return productAvailableUnitOtherCharge;
}
public void setProductAvailableUnitOtherCharge(double productAvailableUnitOtherCharge) {
this.productAvailableUnitOtherCharge = productAvailableUnitOtherCharge;
}
public Lot getLot() {
return lot;
}
public void setLot(Lot lot) {
this.lot = lot;
}
}
I am using hibernate-validator4.1.0.Final and JSR 303 for validation.
As you can see that I have two model classes Lot and ProductAvailable with mapping OneToMany that means one Lot can have Many ProductAvailable.
My Problem is: My custom annotaion IsUnit working fine with class Lot but throwing exception in case of class ProductAvailable.
Exception is:
javax.validation.ConstraintViolationException: Validation failed for classes [com.rapidtech.rapidtechorganic.model.ProductAvailable] during persist time for groups [javax.validation.groups.Default, ]
List of constraint violations:[
ConstraintViolationImpl{interpolatedMessage='Please Enter a valid UNIT e.g. kg,litre,ton', propertyPath=productAvailableUnit, rootBeanClass=class com.rapidtech.rapidtechorganic.model.ProductAvailable, messageTemplate='Please Enter a valid UNIT e.g. kg,litre,ton'}
]
org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:138)
org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreInsert(BeanValidationEventListener.java:78)
org.hibernate.action.internal.EntityInsertAction.preInsert(EntityInsertAction.java:205)
org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:82)
org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:560)
org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:434)
org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)
org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1295)
org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:468)
org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3135)
org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2352)
org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:485)
org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:147)
org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:231)
org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:65)
com.rapidtech.rapidtechorganic.dao.AbstractDao.save(AbstractDao.java:30)
com.rapidtech.rapidtechorganic.dao.lot.LotDaoImpl.save(LotDaoImpl.java:22)
com.rapidtech.rapidtechorganic.service.LotServiceImpl.save(LotServiceImpl.java:25)
com.rapidtech.rapidtechorganic.controller.LotController.saveLotController(LotController.java:59)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
My Controller class looks like this:
#RequestMapping(value = "/saveLot", method = RequestMethod.POST)
public ModelAndView saveLotController(#Valid #ModelAttribute(value="lot") Lot lot, BindingResult result) {
ModelAndView model;
if(result.hasErrors()){
model = new ModelAndView("saveLotForm");
}
else {
Services lotService = (LotServiceImpl) appContext.getBean("lotServiceImpl");
lot.getProductAvailable().setLot(lot);
lotService.save(lot);
model = new ModelAndView("Success");
model.addObject("successMessage","Lot "+lot.getLotName()+" Saved Successfully!");
}
return model;
}
Any help would be appreaciated and Thanks in Advance.
Afte doing some research I have found the solution. All I need to put #Valid annotation over my productAvailable member variable of class Lot
Then it will check the validation for my ProductAvailable class.
How to Validate different model class into one form using Spring MVC JSR-303 Validator

How to specify spring-data-rest version in spring-boot project?

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!

Error with OpenJPA and processing a class

This is the error shown:
exception
<openjpa-2.3.0-r422266:1540826 fatal user error> org.apache.openjpa.persistence.ArgumentException: An error occurred while processing registered class "class no.avexis.fjellkam.Models.Cabin".
org.apache.openjpa.meta.MetaDataRepository.processRegisteredClasses(MetaDataRepository.java:1684)
org.apache.openjpa.meta.ClassMetaData.getPCSubclasses(ClassMetaData.java:376)
org.apache.openjpa.jdbc.meta.MappingRepository.findBaseClassMapping(MappingRepository.java:1539)
org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRepository.java:402)
org.apache.openjpa.meta.MetaDataRepository.preMapping(MetaDataRepository.java:769)
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:658)
org.apache.openjpa.meta.MetaDataRepository.getMetaDataInternal(MetaDataRepository.java:418)
org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:389)
org.apache.openjpa.enhance.ManagedClassSubclasser.configureMetaData(ManagedClassSubclasser.java:227)
org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(ManagedClassSubclasser.java:182)
org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(AbstractBrokerFactory.java:312)
org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:236)
org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:212)
org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:155)
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:226)
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:153)
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:59)
no.avexis.fjellkam.DAO.AdminDAO.getEvents(AdminDAO.java:161)
no.avexis.fjellkam.Controllers.Common.ArticleServlet.doGet(ArticleServlet.java:33)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.IllegalStateException: Can't overwrite cause with java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [org.apache.openjpa.util.IntId]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
java.lang.Throwable.initCause(Throwable.java:457)
org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1324)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1203)
java.lang.ClassLoader.loadClass(ClassLoader.java:411)
java.lang.ClassLoader.loadClass(ClassLoader.java:357)
org.apache.openjpa.enhance.no$avexis$fjellkam$Models$Cabin$pcsubclass.pcNewObjectIdInstance(Unknown Source)
org.apache.openjpa.enhance.PCRegistry.newObjectId(PCRegistry.java:140)
org.apache.openjpa.meta.MetaDataRepository.processRegisteredClass(MetaDataRepository.java:1731)
org.apache.openjpa.meta.MetaDataRepository.processRegisteredClasses(MetaDataRepository.java:1681)
org.apache.openjpa.meta.ClassMetaData.getPCSubclasses(ClassMetaData.java:376)
org.apache.openjpa.jdbc.meta.MappingRepository.findBaseClassMapping(MappingRepository.java:1539)
org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRepository.java:402)
org.apache.openjpa.meta.MetaDataRepository.preMapping(MetaDataRepository.java:769)
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:658)
org.apache.openjpa.meta.MetaDataRepository.getMetaDataInternal(MetaDataRepository.java:418)
org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:389)
org.apache.openjpa.enhance.ManagedClassSubclasser.configureMetaData(ManagedClassSubclasser.java:227)
org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(ManagedClassSubclasser.java:182)
org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(AbstractBrokerFactory.java:312)
org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:236)
org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:212)
org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:155)
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:226)
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:153)
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:59)
no.avexis.fjellkam.DAO.AdminDAO.getEvents(AdminDAO.java:161)
no.avexis.fjellkam.Controllers.Common.ArticleServlet.doGet(ArticleServlet.java:33)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.ClassNotFoundException
org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1323)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1203)
java.lang.ClassLoader.loadClass(ClassLoader.java:411)
java.lang.ClassLoader.loadClass(ClassLoader.java:357)
org.apache.openjpa.enhance.no$avexis$fjellkam$Models$Cabin$pcsubclass.pcNewObjectIdInstance(Unknown Source)
org.apache.openjpa.enhance.PCRegistry.newObjectId(PCRegistry.java:140)
org.apache.openjpa.meta.MetaDataRepository.processRegisteredClass(MetaDataRepository.java:1731)
org.apache.openjpa.meta.MetaDataRepository.processRegisteredClasses(MetaDataRepository.java:1681)
org.apache.openjpa.meta.ClassMetaData.getPCSubclasses(ClassMetaData.java:376)
org.apache.openjpa.jdbc.meta.MappingRepository.findBaseClassMapping(MappingRepository.java:1539)
org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRepository.java:402)
org.apache.openjpa.meta.MetaDataRepository.preMapping(MetaDataRepository.java:769)
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:658)
org.apache.openjpa.meta.MetaDataRepository.getMetaDataInternal(MetaDataRepository.java:418)
org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:389)
org.apache.openjpa.enhance.ManagedClassSubclasser.configureMetaData(ManagedClassSubclasser.java:227)
org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(ManagedClassSubclasser.java:182)
org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(AbstractBrokerFactory.java:312)
org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:236)
org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:212)
org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:155)
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:226)
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:153)
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:59)
no.avexis.fjellkam.DAO.AdminDAO.getEvents(AdminDAO.java:161)
no.avexis.fjellkam.Controllers.Common.ArticleServlet.doGet(ArticleServlet.java:33)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Here is how I have class file looks like:
package no.avexis.fjellkam.Models;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name = "CABIN")
public class Cabin implements Serializable {
private static final long serialVersionUID = -9160490433220569097L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer cabinID;
private String cabin;
private String title;
private String description;
public Cabin() {
this.cabin = "";
this.title = "";
this.description = "";
}
public Cabin(String cabin, String title, String description) {
this.cabin = cabin;
this.title = title;
this.description = description;
}
public String getCabin() {
return cabin;
}
public void setCabin(String cabin) {
this.cabin = cabin;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getCabinID() {
return cabinID;
}
}
I keep getting this error for all my classes, and I either must be overlooking something, or I've done something very wrong.
It would seem as though there is an error while parsing the class, or locating the class?

Resources