Jasypt encryption stops working after upgrade to JDK 7u261 - spring

We recently upgraded to JDK 7u261 from JDK 7u251 as the new release was available to Java SE support customers on April 15, 2020. The Jasypt encryption stopped working after this Java version upgrade. I receive the following error message;
org.jasypt.exceptions.EncryptionInitializationException: java.lang.ExceptionInInitializerError
at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.initialize(StandardPBEByteEncryptor.java:773)
at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.initialize(StandardPBEStringEncryptor.java:566)
at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:718)
at org.jasypt.properties.PropertyValueEncryptionUtils.decrypt(PropertyValueEncryptionUtils.java:72)
at org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfigurer.convertPropertyValue(EncryptablePropertyPlaceholderConfigurer.java:111)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.convertProperty(PropertyResourceConfigurer.java:121)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.convertProperties(PropertyResourceConfigurer.java:104)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:81)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:669)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5136)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5662)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1007)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:983)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:639)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1296)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:2038)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:622)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ExceptionInInitializerError
at com.ibm.icu.impl.NormalizerDataReader.<clinit>(NormalizerDataReader.java:300)
at com.ibm.icu.impl.NormalizerImpl.<init>(NormalizerImpl.java:288)
at com.ibm.icu.impl.NormalizerImpl.<clinit>(NormalizerImpl.java:35)
at com.ibm.icu.text.Normalizer$Mode.normalize(Normalizer.java:188)
at com.ibm.icu.text.Normalizer.normalize(Normalizer.java:1177)
at com.ibm.icu.text.Normalizer.normalize(Normalizer.java:1146)
at org.jasypt.normalization.Normalizer.normalizeWithIcu4j(Normalizer.java:205)
at org.jasypt.normalization.Normalizer.normalizeToNfc(Normalizer.java:129)
at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.initialize(StandardPBEByteEncryptor.java:718)
... 26 more
Caused by: java.lang.IllegalArgumentException: Invalid version number: Version number may be negative or greater than 255
at com.ibm.icu.util.VersionInfo.getInstance(VersionInfo.java:188)
at com.ibm.icu.impl.ICUDebug.getInstanceLenient(ICUDebug.java:65)
at com.ibm.icu.impl.ICUDebug.<clinit>(ICUDebug.java:69)
... 35 more
The code used in the applicationContext.xml is as follows;
<bean id="encryptorConfig" class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
<property name="algorithm" value="PBEWithMD5AndDES" />
<property name="passwordEnvName" value="APP_ENCRYPTION_PASSWORD" />
</bean>
<bean id="encryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
<property name="config" ref="encryptorConfig" />
</bean>
<bean class="org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfigurer">
<constructor-arg ref="encryptor" />
<property name="locations">
<list>
<value>/WEB-INF/spring.properties</value>
</list>
</property>
</bean>

Try adding a more recent icu4j dependency. See also the following bug report in the Jasypt project: "Encryption stops working after upgrade to Java™ SE Development Kit 7, Update 261 (JDK 7u261)".
The mentioned bug fix updated to:
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>67.1</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>

Related

Why does Flexy-Pool cause a NoSuchElementException when configured via Spring in Apache Storm

I have an Apache Storm (1.1.1) based application, which uses Spring (5.0.3) to configure and inject Hibernate-based (5.2.12) database services, which connect to a PostgreSQL database.
Between Hibernate and the database, I have configured flexy-pool (2.0.0) on top of HikariCP (2.7.6) as a datasource (see Figure A). The application is launched on some Ubuntu 16.04 LTS server instances with the latest OpenJDK 8 version.
I experience sad runtime exceptions related to flexy-pool after starting my Storm topology. However, this is not deterministic. Sometimes it will work, sometimes the exception below will be thrown. If I do not use flexy-pool in my application (see Figure B) everything works everytime as expected.
Caused by:
org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.vladmihalcea.flexypool.config.Configuration]: Factory method 'build' threw exception; nested exception is java.util.NoSuchElementException at
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) at
org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:579) ... 42 more
Caused by:
java.util.NoSuchElementException at
sun.misc.URLClassPath$1.nextElement(URLClassPath.java:282) at
sun.misc.URLClassPath$1.nextElement(URLClassPath.java:256) at
java.net.URLClassLoader$3$1.run(URLClassLoader.java:603) at
java.net.URLClassLoader$3$1.run(URLClassLoader.java:599) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader$3.next(URLClassLoader.java:598) at
java.net.URLClassLoader$3.hasMoreElements(URLClassLoader.java:623) at
sun.misc.CompoundEnumeration.next(CompoundEnumeration.java:45) at
sun.misc.CompoundEnumeration.nextElement(CompoundEnumeration.java:58) at
java.util.ServiceLoader$LazyIterator.hasNextService(ServiceLoader.java:357) at
java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:393) at
java.util.ServiceLoader$1.hasNext(ServiceLoader.java:474) at
com.vladmihalcea.flexypool.metric.MetricsFactoryResolver.resolve(MetricsFactoryResolver.java:27) at
com.vladmihalcea.flexypool.config.Configuration$Builder.build(Configuration.java:165) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at
java.lang.reflect.Method.invoke(Method.java:498) at
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
The Spring configuration used in Figure B is this one (based on the official sample):
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<property name="poolName" value="springHikariCP"/>
<property name="connectionTestQuery" value="SELECT 1"/>
<property name="dataSourceClassName" value="${gmetric.dataSourceClassName}"/>
<property name="dataSourceProperties">
<props>
<prop key="url">${shc.gmetric.url}</prop>
<prop key="user">${shc.gmetric.username}</prop>
<prop key="password">${shc.gmetric.pw}</prop>
</props>
</property>
</bean>
<bean id="poolingDataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<constructor-arg ref="hikariConfig"/>
</bean>
<bean id="configurationBuilder" class="com.vladmihalcea.flexypool.config.Configuration$Builder">
<constructor-arg value="uniqueId"/>
<constructor-arg ref="poolingDataSource"/>
<constructor-arg value="#{ T(com.vladmihalcea.flexypool.adaptor.HikariCPPoolAdapter).FACTORY }"/>
</bean>
<bean id="configuration" factory-bean="configurationBuilder" factory-method="build"/>
<bean id="flexyPoolDataSource" class="com.vladmihalcea.flexypool.FlexyPoolDataSource" init-method="start" destroy-method="stop">
<constructor-arg ref="configuration"/>
<constructor-arg>
<array>
<bean class="com.vladmihalcea.flexypool.strategy.IncrementPoolOnTimeoutConnectionAcquiringStrategy.Factory">
<constructor-arg value="5"/>
</bean>
<bean class="com.vladmihalcea.flexypool.strategy.RetryConnectionAcquiringStrategy.Factory">
<constructor-arg value="2"/>
</bean>
</array>
</constructor-arg>
</bean>
<bean id="entityManagerFactoryGMetrics"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="flexyPoolDataSource"/>
<property name="persistenceUnitName" value="${gmetric.context.name}"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<!--<property name="generateDdl" value="true" />-->
<property name="databasePlatform" value="${hibernate.dialect}"/>
<property name="showSql" value="${hibernate.showSQL}"/>
</bean>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.connection.driver_class">${gmetric.driverClassName}</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.showSQL}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
</props>
</property>
</bean>
My questions are:
Is my Spring-based (default) configuration for flexy-pool correct?
Is there a solution to prevent this runtime exception related to flexy-pool?
What is the cause for this NoSuchElementException?
I found, that Dropwizard Metrics 4 (which is required by flexy-pool) was missing in my shaded jar and therefore this wired runtime exception occured:
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>${metrics.version}</version>
</dependency>
According to the author this is related to the way flexy-pool detects the related Dropwizard Metrics handler (as it supports DM3 and DM4, which cannot be used interchangeably).

IBM WAS Liberty Error + missing type com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource

I'm converting a glassfish project over to IBM WAS Liberty, with much difficulty I am presently having an issue accessing my connection pool configured in Liberty (server.xml) utilizing jndi (jdbc/dataphile).
I contuinually get a missing type com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource error.
Here is some more added detail:
<library id="DB2JCC4Lib">
<fileset dir="C:/MyApps/db2/jdbc" id="db-fileset" includes="db2jcc4-9.5.jar"/>
</library>
<dataSource id="dataSource" jndiName="jdbc/dataphile" type="javax.sql.DataSource">
<jdbcDriver libraryRef="DB2JCC4Lib"/>
<connectionManager minPoolSize="2" numConnectionsPerThreadLocal="10"/>
<properties.db2.jcc databaseName="DUNDEEPD" id="DataphileProperties" password="username" portNumber="30001" serverName="xxx.xx.xxx.xxx" user="username"/>
</dataSource>
My stack trace is below;
[ERROR ] Context initialization failed
Caused by: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException: warning can't determine modifiers of missing type com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource
[Xlint:cantFindType]
at org.aspectj.weaver.reflect.ReflectionWorld$ExceptionBasedMessageHandler.handleMessage(ReflectionWorld.java:129)
at org.aspectj.weaver.Lint$Kind.signal(Lint.java:340)
at org.aspectj.weaver.MissingResolvedTypeWithKnownSignature.raiseCantFindType(MissingResolvedTypeWithKnownSignature.java:232)
at org.aspectj.weaver.MissingResolvedTypeWithKnownSignature.getModifiers(MissingResolvedTypeWithKnownSignature.java:104)
at org.aspectj.weaver.ResolvedType.isInterface(ResolvedType.java:876)
at org.aspectj.weaver.ResolvedType.getHierarchy(ResolvedType.java:355)
at org.aspectj.weaver.patterns.KindedPointcut.fastMatch(KindedPointcut.java:126)
at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.couldMatchJoinPointsInType(PointcutExpressionImpl.java:84)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:238)
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:200)
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:254)
at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:286)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:117)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:87)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:68)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:359)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:322)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:407)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1561)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:162)
... 58 more
I am not an expert on this but a similar problem was reported here:
https://developer.ibm.com/answers/questions/9498/datasource-issue-on-liberty-in-spring-hibernate-application.html
The solution required adding this to the datasource:
<property name="resourceRef" value="true" />
<property name="expectedType" value="javax.sql.DataSource"/>
Try creating META-INF/aop.xml file as described in the following post: Why aspect j can't weave show Xlint cantFindType and exclude the com.ibm.ws.rsadapter.jdbc.* classes or better yet, include only your application classes.
I do have enough theory as to why, but this is how I fundamentally how to fix my issue:
Originally, in my Spring XML schema configuration, I had the following:
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/mydatasource" />
But I had to convert it to the following:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/mydatasource" />
<property name="lookupOnStartup" value="false"/>
<property name="cache" value="true" />
<property name="proxyInterface" value="javax.sql.DataSource" />
</bean>
So essentially as suggested I had to enforce this configuration change which added the following properties:
<property name="proxyInterface" value="javax.sql.DataSource"
Hopefully that help someone else out there
Thanks

persistence.xml property values from properties file

I have below configuration for entityManger
<jee:jndi-lookup id="dataSource" expected-type="javax.sql.DataSource"
jndi-name="java:jboss/datasources/AppDS"/>
<jee:jndi-lookup id="entityManagerFactory"
expected-type="javax.persistence.EntityManagerFactory"
jndi-name="java:comp/env/persistence/appPersistenceUnit"/>
I also have persistence.xml file, now I want to add hibernate-search feature to my application, so I have added below properties in my persistence.xml file ..
<property name="hibernate.search.default.directory_provider" value="filesystem" />
<property name="hibernate.search.default.indexBase" value="/var/lucene/indexes" />
Here I want to externalize indexBase property value to properties file, something like this.
<property name="hibernate.search.default.indexBase" value="${index.location}" />
Can any please suggest how I can achieve this ?
I am using Spring version : 4.
Thanks.
Update - 2
I have added below code to my application-context.xml
Commented this
<jee:jndi-lookup id="entityManagerFactory"
expected-type="javax.persistence.EntityManagerFactory"
jndi-name="java:comp/env/persistence/appPersistenceUnit"/>
and added below bean configuration ..
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.search.default.indexBase">/var/lucene/indexes</prop>
</props>
</property>
</bean>
But after server restart it give below exception.. but if i keep same property in persistence.xml it works fine ..
Exception: Error creating bean with name 'entityManagerFactory' defined in URL [vfs:/D:/App/Projects/Projects/wildfly/bin/content/app.war/WEB-INF/classes/META-INF/spring/appContext-web.xml]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unabl
e to create requested service [org.hibernate.engine.spi.CacheImplementor]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553) [spring-beans-4.0.1.R
ELEASE.jar:4.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) [spring-beans-4.0.1.RELE
ASE.jar:4.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) [spring-beans-4.0.1.RELEAS
E.jar:4.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) [spring-beans-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) [spring-beans-4.0.1.RELEASE.jar:4.0.
1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) [spring-beans-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) [spring-beans-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:973) [spring-context-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:750) [spring-context-4.0.1.RELEA
SE.jar:4.0.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) [spring-context-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) [spring-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) [spring-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:173) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:187) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:86)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.start(UndertowDeploymentService.java:71)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_71]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_71]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_71]
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.spi.CacheImplementor]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:233) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:197) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:272) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) [hibernate-entitymanager-4.3.1.Final.jar:4.
3.1.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843) [hibernate-entitymanager-4.3.1.Final.jar:4.
3.1.Final]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:399) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.
Final]
at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:150) [hibernate-entitymanager-4.3.1.Final.
jar:4.3.1.Final]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:336) [spring-or
m-4.0.1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318) [spring-orm-4.0.1.RELEASE.jar:4.0.1.
RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) [spring-beans-4.0.
1.RELEASE.jar:4.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549) [spring-beans-4.0.1.R
ELEASE.jar:4.0.1.RELEASE]
... 21 more
Caused by: org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is
not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level c
ache provider (hibernate-infinispan, e.g.) is available on the classpath.
at org.hibernate.cache.internal.NoCachingRegionFactory.buildTimestampsRegion(NoCachingRegionFactory.java:105) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.cache.spi.UpdateTimestampsCache.<init>(UpdateTimestampsCache.java:73) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.internal.CacheImpl.<init>(CacheImpl.java:72) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:40) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:35) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.initiateService(SessionFactoryServiceRegistryImpl.java:91) [hibernate-core-4.3.1.Final.jar:4.3
.1.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:223) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
... 34 more
18:14:59,612 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-6) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./app: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./app: Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.0.Final.jar:1.2.0.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_71]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_71]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_71]
Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [vfs:/
D:/Projects/wildfly/bin/content/app.war/WEB-INF/classes/META-INF/spring/appContext-web.xml]: Invocation of ini
t method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.spi.CacheImplementor]
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:216)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:86)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.start(UndertowDeploymentService.java:71)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.0.Final.jar:1.2.0.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.0.Final.jar:1.2.0.Final]
... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [vfs:/D:/Pro
jects/wildfly/bin/content/app.war/WEB-INF/classes/META-INF/spring/appContext-web.xml]: Invocation of init method failed; nested exce
ption is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.spi.CacheImplementor]
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:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:973)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:750)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:173)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:187)
... 7 more
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.spi.CacheImplementor]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:233)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:197)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:272)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:399)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:150)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:336)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
... 21 more
Caused by: org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is
not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level c
ache provider (hibernate-infinispan, e.g.) is available on the classpath.
at org.hibernate.cache.internal.NoCachingRegionFactory.buildTimestampsRegion(NoCachingRegionFactory.java:105)
at org.hibernate.cache.spi.UpdateTimestampsCache.<init>(UpdateTimestampsCache.java:73)
at org.hibernate.internal.CacheImpl.<init>(CacheImpl.java:72)
at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:40)
at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:35)
at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.initiateService(SessionFactoryServiceRegistryImpl.java:91)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:223)
... 34 more
Also, i wanted to check what is the use of configLocation in LocalContainerEntityManagerFactoryBean ?
Thanks.
Update - 3
Sorry, I didn't provide full information, in my existing persistence.xml file
hibernate.cache.use_second_level_cache was already set to true, and it was working fine.
But in next requirement I had to implement search feature, so I used hibernate-search. And I have added hibernate.search.default.indexBase and hibernate.search.default.directory_provider in persistence.xml, after that it's working fine. It created index when entity is checked in, also updates index when entity is updated..
As I have to deploy this code on different environment, i have to specify different location for each environment. For all environments i have different properties files. So i want to do same for this hibernate.search.default.indexBase as well.. but after adding implementation as you suggested, still its not working ..
let me know if I can help you with any other information to find out solution ...
Update - 4
Below is my persistence.xml file ..
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="appPersistenceUnit"
transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/AppDS</jta-data-source>
<class>com.app.domain.User</class>
<!-- Other entity classes -->
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
<property name="jboss.entity.manager.factory.jndi.name"
value="persistence-units/appPersistenceUnit"/>
<property name="hibernate.transaction.jta.platform"
value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform"/>
<!-- Disable transaction auto commit (production) -->
<property name="hibernate.connection.autocommit" value="false"/>
<!-- Default character set -->
<property name="hibernate.connection.charSet" value="UTF-8"/>
<!-- Enable Hibernate's automatic session context management -->
<property name="hibernate.current_session_context_class"
value="jta"/>
<!-- SQL dialect -->
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<!-- Naming strategy -->
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
<!-- Format SQL outpout -->
<property name="hibernate.format_sql" value="false"/>
<!-- Enabling Statistics -->
<property name="hibernate.generate_statistics" value="false"/>
<!-- value="create" to build a new database on each run; value="update"
to modify an existing database; value="create-drop" means the same as "create"
but also drops tables when Hibernate closes; value="validate" makes no changes
to the database -->
<property name="hibernate.hbm2ddl.auto" value="validate"/>
<!-- Enable batch procession using an integer between 10-50 -->
<property name="hibernate.jdbc.batch_size" value="40"/>
<!-- Echo all executed SQL to stdout -->
<property name="hibernate.show_sql" value="false"/>
<!-- Envers -->
<property name="org.hibernate.envers.audit_strategy"
value="org.hibernate.envers.strategy.ValidityAuditStrategy"/>
<property
name="org.hibernate.envers.audit_strategy_validity_end_rev_field_name"
value="revision_end"/>
<property
name="org.hibernate.envers.audit_strategy_validity_store_revend_timestamp"
value="true"/>
<property
name="org.hibernate.envers.audit_strategy_validity_revend_timestamp_field_name"
value="revision_end_time"/>
<property name="org.hibernate.envers.audit_table_suffix" value="_aud"/>
<property name="org.hibernate.envers.revision_field_name" value="revision"/>
<property name="org.hibernate.envers.revision_type_field_name" value="revision_type"/>
<property name="org.hibernate.envers.revision_listener"
value="com.app.listener.revision.RevisionListenerImpl"/>
<!-- Infinispan -->
<!-- Enables the query cache. You still need to set individual queries
to be cacheable. Call org.hibernate.Query.setCacheable(true) to initiate. -->
<property name="hibernate.cache.use_query_cache" value="true"/>
<!-- Enable second level cache. Requires session flushing. -->
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<!-- Hibernate Search properties -->
<property name="hibernate.search.default.directory_provider" value="filesystem" />
<property name="hibernate.search.default.indexBase" value="/var/lucene/indexes" />
</properties>
</persistence-unit>
</persistence>
and, below is my spring configuration file, also i have added <bean> configuration which i tried after your inputs, which is commented below jee:jndi-lookup
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd">
<jee:jndi-lookup id="dataSource" expected-type="javax.sql.DataSource"
jndi-name="java:jboss/datasources/AppDS"/>
<jee:jndi-lookup id="entityManagerFactory"
expected-type="javax.persistence.EntityManagerFactory"
jndi-name="java:comp/env/persistence/appPersistenceUnit"/>
<!-------------------------
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.search.default.indexBase">/var/lucene/indexes</prop>
</props>
</property>
</bean>
-->
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager"/>
<bean id="entityManager"
class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean id="exceptionTranslator"
class="org.springframework.orm.hibernate4.HibernateExceptionTranslator"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
</beans>
Let me know if you want me to add any other details . .
Thanks ..
Since the persistence.xml lies outside the spring it isn't possible to inject properties via spring property placeholder.
The inherited method setJpaProperties of Springs' LocalContainerEntityManagerFactoryBean will solve the purpose you are looking forward too.
Sample spring bean configuration would look something like below -
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.search.default.indexBase">${index.location}</prop>
</props>
</property>
Note that this will still read the configuration from persistence.xml with additional facilities. (e.g. customized location for persistence.xml instead of default META-INF)

Receiving NullPointerException while using Jasypt and Spring Security 3.1

I am trying to configure Jasypt with Spring Security. My configuration file looks like this:
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:8090/sample
jdbc.username=ENC(*****) where the *****=the salted username
jdbc.password=ENC(*****) where the *****=the salted password
My servlet xml contains the proper bean setup in this format:
<bean id="propertyPlaceholderConfigurer"
class="org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer">
<constructor-arg ref="configurationEncryptor" />
<property name="location" value="/WEB-INF/jdbc.properties" />
</bean>
<bean id="configurationEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
<property name="config" ref="environmentVariablesConfiguration" />
</bean>
<bean id="environmentVariablesConfiguration"
class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
<property name="algorithm" value="PBEWithMD5AndDES" />
<property name="passwordEnvName" value="APP_ENCRYPTION_PASSWORD" />
<!--<property name="password" value="**********" />-->
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
My environment variable is set in windows properly for APP_ENCRYPTION_PASSWORD. It is visible when I echo it from command line. When I use this setup, I get the null pointer stack trace below. When I use the hard coded salt password "-->", my application runs smoothly. Can someone show me why Jasypt or Spring might not be picking up on my environment variable properly? Any information would be welcomed. Thanks.
org.springframework.web.context.ContextLoader initWebApplicationContext
SEVERE: Context initialization failed
java.lang.NullPointerException
at org.jasypt.encryption.pbe.config.SimplePBEConfig.getPasswordCharArray(SimplePBEConfig.java:434)
at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.resolveConfigurationPassword(StandardPBEByteEncryptor.java:740)
at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.initialize(StandardPBEByteEncryptor.java:590)
at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.initialize(StandardPBEStringEncryptor.java:553)
at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:705)
at org.jasypt.properties.PropertyValueEncryptionUtils.decrypt(PropertyValueEncryptionUtils.java:72)
at org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer.convertPropertyValue(EncryptablePropertyPlaceholderConfigurer.java:109)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.convertProperty(PropertyResourceConfigurer.java:121)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.convertProperties(PropertyResourceConfigurer.java:104)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:81)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:662)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:388)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:293)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4701)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5204)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5199)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Aug 7, 2013 8:46:15 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NullPointerException
at org.jasypt.encryption.pbe.config.SimplePBEConfig.getPasswordCharArray(SimplePBEConfig.java:434)
at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.resolveConfigurationPassword(StandardPBEByteEncryptor.java:740)
at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.initialize(StandardPBEByteEncryptor.java:590)
at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.initialize(StandardPBEStringEncryptor.java:553)
at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:705)
at org.jasypt.properties.PropertyValueEncryptionUtils.decrypt(PropertyValueEncryptionUtils.java:72)
at org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer.convertPropertyValue(EncryptablePropertyPlaceholderConfigurer.java:109)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.convertProperty(PropertyResourceConfigurer.java:121)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.convertProperties(PropertyResourceConfigurer.java:104)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:81)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:662)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:388)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:293)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4701)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5204)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5199)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
May be you can try restarting windows command prompt and try again.
I got similar error and after setting up env variable, I forgot to restart windows command prompt and was getting same error.
Restarting windows command prompt resolved this issue for me.
For anyone else facing this issue and stumbling upon this question, restarting Eclipse fixed the issue.
Note: you must close Eclipse fully then re-open. Clicking "Restart" won't work as it doesn't kill the Java process completely.
In my case it was an environment variable we were counting on to use as seed
Whoever has created your setup readme, read it
:)
If you are in Linux environment,
type:
export APP_ENCRYPTION_PASSWORD=CUSTOM_KEY
If you are in Windows environment, set the environment variable:
set APP_ENCRYPTION_PASSWORD as variable, set CUSTOM_KEY as value

Websphere: JPA: java.lang.IllegalArgumentException: Object: Entity is not a known entity type

I'm trying to deploy an app using Eclipselink as my JPA Layer on IBM Websphere 7.0.0.9. While trying to do any CRUD operations, i get the following exception:
Caused by: java.lang.IllegalArgumentException: Object: Entity is not a known entity type.
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4199)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:380)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:600)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:358)
at $Proxy93.persist(Unknown Source)
... 89 more
Another stack trace i see is :
Caused by: java.lang.ClassCastException: Entity incompatible with Entity
at o.u.d.dao.jpa.converter.impl.EntityBeanConvertorImpl.convertToModel(EntityBeanConvertorImpl.java:143)
... 223 more
My persistence.xml looks like:
<persistence-unit name="ds" transaction-type="JTA"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <jta-data-source>dsjta</jta-data-source> <class>Entity</class> <exclude-unlisted-classes>true</exclude-unlisted-classes> <properties> <property name="eclipselink.target-server" value="WebSphere_7" /> <property name="eclipselink.logging.level" value="OFF" /> <property name="eclipselink.ddl-generation" value="none" /> <property name="eclipselink.ddl-generation.output-mode" value="database" /> </properties> </persistence-unit>
My application context file looks like:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceUnitName" value="ds"/> <property name="dataSource" ref="dataSource"/> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"> <property name="showSql" value="false"/> <property name="generateDdl" value="false"/> </bean> </property> <property name="loadTimeWeaver"> <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/> </property> </bean>
Our VM is started with the -javaagent parameter specified and pointing to spring-agent.jar What could be the reason for these exceptions?
The issue here is there is no Spring LoadTimeWeaver for Websphere. When your application attempts to combine a Web-Tier application with the Spring managed EM while using the InstrumentationLoadTimeWeaver class cast exceptions result. EclipseLink supports weaving in all JPA 2 compliant containers but in this case Spring is acting as an intermediary and interfering with the weaving.
Until Spring has a LoadTimeWeaver for Websphere You will need to remove the InstrumentationLoadTimeWeaver and set the EclipseLink persistence.xml property "eclipselink.weaving" to false or use the Static weaver.

Resources