5

I have a Spring MVC/Spring-Data-JPA (with Hibernate) application running perfectly on the Websphere 8.5.5 Liberty Profile. However, when I deploy to the full version of Websphere 8.5.5. I get the error pasted below.

My other beans naturally rely on the EntityManagerFactory, so this kills me. Have been googling all day to no avail.

  • Environment: Websphere 8.5.5
  • Spring Version: 4.0.4.RELEASE
  • Hibernate EntityManager Version: 4.3.5
  • IDE: IBM RAD (Version: 8.5.5) (Eclipse 3.6.3)

STACK TRACE:

[5/20/14 19:29:14:800 EDT] 00000070 webapp        I com.ibm.ws.webcontainer.webapp.WebApp log SRVE0292I: Servlet Message - [oceanEAR#ocean.war]:.Initializing Spring root WebApplicationContext
[5/20/14 19:29:14:801 EDT] 00000070 SystemOut     O INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
[5/20/14 19:29:14:804 EDT] 00000070 SystemOut     O INFO : org.springframework.web.context.support.AnnotationConfigWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Tue May 20 19:29:14 EDT 2014]; root of context hierarchy
[5/20/14 19:29:14:872 EDT] 00000070 SystemOut     O INFO : org.springframework.web.context.support.AnnotationConfigWebApplicationContext - Registering annotated classes: [class com.mycompany.myapp.config.AppConfig]
[5/20/14 19:29:15:276 EDT] 00000070 SystemOut     O INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
[5/20/14 19:29:15:546 EDT] 00000070 SystemOut     O WARN : org.hibernate.ejb.HibernatePersistence - HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
[5/20/14 19:29:15:737 EDT] 00000070 SystemOut     O WARN : org.hibernate.jpa.boot.archive.internal.JarInputStreamBasedArchiveDescriptor - HHH015010: Unable to find file (ignored): bundleresource://130.fwk884063730/
java.lang.NullPointerException: in is null
        at java.util.zip.ZipInputStream.<init>(ZipInputStream.java:75)
        at java.util.jar.JarInputStream.<init>(JarInputStream.java:69)
        at java.util.jar.JarInputStream.<init>(JarInputStream.java:55)
        at org.hibernate.jpa.boot.archive.internal.JarInputStreamBasedArchiveDescriptor.visitArchive(JarInputStreamBasedArchiveDescriptor.java:73)
        at org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:72)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.scan(EntityManagerFactoryBuilderImpl.java:723)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:219)
        at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:51)
        at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:182)
        at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:177)
        at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:152)
        at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:67)
        at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:290)
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
        at com.mycompany.myapp.config.AppConfig.entityManagerFactory(AppConfig.java:59)
        at com.mycompany.myapp.config.AppConfig$$EnhancerBySpringCGLIB$$a99458c6.CGLIB$entityManagerFactory$1(<generated>)
        at com.mycompany.myapp.config.AppConfig$$EnhancerBySpringCGLIB$$a99458c6$$FastClassBySpringCGLIB$$b6194988.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)
        at com.mycompany.myapp.config.AppConfig$$EnhancerBySpringCGLIB$$a99458c6.entityManagerFactory(<generated>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
        at java.lang.reflect.Method.invoke(Method.java:611)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:586)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
        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.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
        at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:632)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:442)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:276)
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129)
        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: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.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1017)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:960)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:858)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
        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: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.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1017)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:960)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:858)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
        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: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.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
        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 com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:1682)
        at com.ibm.ws.webcontainer.webapp.WebAppImpl.initialize(WebAppImpl.java:414)
        at com.ibm.ws.webcontainer.webapp.WebGroupImpl.addWebApplication(WebGroupImpl.java:88)
        at com.ibm.ws.webcontainer.VirtualHostImpl.addWebApplication(VirtualHostImpl.java:169)
        at com.ibm.ws.webcontainer.WSWebContainer.addWebApp(WSWebContainer.java:749)
        at com.ibm.ws.webcontainer.WSWebContainer.addWebApplication(WSWebContainer.java:634)
        at com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:426)
        at com.ibm.ws.webcontainer.component.WebContainerImpl.start(WebContainerImpl.java:718)
        at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:1175)
        at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:1370)
        at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:639)
        at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:968)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:774)
        at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplicationDynamically(ApplicationMgrImpl.java:1374)
        at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:2179)
        at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:445)
        at com.ibm.ws.runtime.component.CompositionUnitImpl.start(CompositionUnitImpl.java:123)
        at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:388)
        at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.access$500(CompositionUnitMgrImpl.java:116)
        at com.ibm.ws.runtime.component.CompositionUnitMgrImpl$1.run(CompositionUnitMgrImpl.java:663)
        at com.ibm.ws.security.auth.ContextManagerImpl.runAs(ContextManagerImpl.java:5474)
        at com.ibm.ws.security.auth.ContextManagerImpl.runAsSystem(ContextManagerImpl.java:5600)
        at com.ibm.ws.security.core.SecurityContext.runAsSystem(SecurityContext.java:255)
        at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.startCompositionUnit(CompositionUnitMgrImpl.java:677)
        at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.startCompositionUnit(CompositionUnitMgrImpl.java:621)
        at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:1266)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
        at java.lang.reflect.Method.invoke(Method.java:611)
        at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:69)
        at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
        at java.lang.reflect.Method.invoke(Method.java:611)
        at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:272)
        at javax.management.modelmbean.RequiredModelMBean$4.run(RequiredModelMBean.java:1148)
        at java.security.AccessController.doPrivileged(AccessController.java:298)
        at com.ibm.oti.security.CheckedAccessControlContext.securityCheck(CheckedAccessControlContext.java:30)
        at sun.misc.JavaSecurityAccessWrapper.doIntersectionPrivilege(JavaSecurityAccessWrapper.java:41)
        at javax.management.modelmbean.RequiredModelMBean.invokeMethod(RequiredModelMBean.java:1142)
        at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:995)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:847)
        at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:783)
        at com.ibm.ws.management.AdminServiceImpl$1.run(AdminServiceImpl.java:1335)
        at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
        at com.ibm.ws.management.AdminServiceImpl.invoke(AdminServiceImpl.java:1228)
        at com.ibm.ws.management.connector.AdminServiceDelegator.invoke(AdminServiceDelegator.java:181)
        at com.ibm.ws.management.connector.ipc.CallRouter.route(CallRouter.java:247)
        at com.ibm.ws.management.connector.ipc.IPCConnectorInboundLink.doWork(IPCConnectorInboundLink.java:360)
        at com.ibm.ws.management.connector.ipc.IPCConnectorInboundLink.ready(IPCConnectorInboundLink.java:132)

Here is my AppConfig class:

package com.mycompany.myapp.config;

import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup;
import org.springframework.orm.hibernate4.HibernateExceptionTranslator;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaDialect;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.support.AbstractPlatformTransactionManager;

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages="com.mycompany.myapp.repository")
@ComponentScan(basePackages={"com.mycompany.myapp.service", "com.mycompany.myapp.domain", "com.mycompany.myapp.transformer"})
public class AppConfig {

    private static final Logger logger = LoggerFactory.getLogger(AppConfig.class);

    @Bean
    public AbstractPlatformTransactionManager transactionManager(){
        JpaTransactionManager txManager = new JpaTransactionManager();
        EntityManagerFactory emf = entityManagerFactory();
        txManager.setEntityManagerFactory(emf);
        txManager.setDataSource(dataSource());
        return txManager;
    }

    @Bean
    public EntityManagerFactory entityManagerFactory(){
        LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
        //DATA SOURCE
        DataSource ds = dataSource();
        emf.setDataSource(ds);
        //JPA VENDOR ADAPTER
        logger.debug("About to create HibernateJpaVendorAdapter.");
        HibernateJpaVendorAdapter jpaAdapter = new HibernateJpaVendorAdapter();

        emf.setJpaVendorAdapter(jpaAdapter);

        //PACKAGES TO SCAN
        emf.setPackagesToScan("com.mycompany.myapp.domain", "com.mycompany.myapp.transformer.rule");
        //JPA PROPERTIES
        Properties jpaProps = new Properties();
        jpaProps.put("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
        jpaProps.put("hibernate.max_fetch_depth", 3);
        jpaProps.put("hibernate.jdbc_fetch_size", 50);
        jpaProps.put("hibernate.jdbc_batch_size", 10);
        jpaProps.put("hibernate.show_sql", true);
        jpaProps.put("hibernate.dynamic-update", true);
        //https://hibernate.atlassian.net/browse/HHH-6962 TRYING TO AVOID HIBERNATE ERROR: HHH015010
        jpaProps.put("hibernate.exclude-unlisted-classes", true);
        emf.setJpaProperties(jpaProps);

        emf.afterPropertiesSet(); 

        logger.debug("JPA Property Map:");
        for (Entry<String, Object> entry : emf.getJpaPropertyMap().entrySet()){
            logger.debug("ENTRY: " + entry.getKey() + "=" + entry.getValue().toString());
        }

        EntityManagerFactory entityManagerFactory = emf.getObject();

        return entityManagerFactory;
    }

    @Bean
    public DataSource dataSource(){
        final JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
        dsLookup.setResourceRef(true);
        DataSource dataSource = dsLookup.getDataSource("jdbc/myapp");
        return dataSource;
    }

    @Bean 
    public HibernateExceptionTranslator hibernateExceptionTranslator(){ 
      return new HibernateExceptionTranslator(); 
    }

}

I'm taking an all-JavaConfig approach to Spring as well as JPA (i.e. I have no persistence.xml file.).

I found the following question, but it doesn't resolve my situation:

JPA entities as a shareable jar not working in a WAR file unde Tomcat 7.0.27

Any ideas?

Community
  • 1
  • 1
Jay Goettelmann
  • 375
  • 1
  • 6
  • 15
  • You should at least change your `entityManagerFactory` method to return the `LocalContainerEntityManagerFactoryBean` and don't call `afterPropertiesSet()` and `getObject()` as that will be taken care of by Spring. What worries me is the warning as that indicates that it cannot find the newer hibernate 4.3 classes (which according to your post you are using). – M. Deinum May 21 '14 at 05:43
  • I have both of those classes on the class path. I've read in a couple places that this was a [Hibernate bug that was supposed to be fixed in the current version.](https://hibernate.atlassian.net/browse/HHH-8625). It's possible this whole problem just stems from the fact that the but is still there. Hoping someone knows for sure. – Jay Goettelmann May 21 '14 at 14:01
  • According to the comments on https://hibernate.atlassian.net/browse/HHH-8625 and the fact that https://hibernate.atlassian.net/browse/HHH-9141 still remains open makes this a hibernate bug. So you can ignore that remarkt and try the solution as outlined in HHH-8625. – M. Deinum May 21 '14 at 14:10
  • Were you able to find an answer? I stepped through the debugger and see that Hibernate JPA is trying to scan for the missing jar file. When I decoded the bundleresource URL it says it is looking for: C:\IBM\WebSphere\AppServer\plugins\com.ibm.ws.runtime.gateway.jar It doesn't find it and just throws this warning and continues. I wonder if there is a way to tell Spring JPA or Hibernate to not scan the full classpath? – Jeff Sheets Jul 23 '14 at 21:39
  • Hey Jeff, never found a solution, fell back to a more traditional xml-based configuration and managed to work around it. :( – Jay Goettelmann Jul 29 '14 at 15:55
  • Hi @JeffSheets, FWIW, M.Deinum configuration helped me. In short, you need to explicitly defined the required bean/properties so that Spring knows what you want. – jumping_monkey Dec 10 '19 at 09:16

1 Answers1

1

Try the following configuration.

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages="com.mycompany.myapp.repository")
@ComponentScan(basePackages={"com.mycompany.myapp.service", "com.mycompany.myapp.domain", "com.mycompany.myapp.transformer"})
public class AppConfig {

    private static final Logger logger = LoggerFactory.getLogger(AppConfig.class);

    @Bean
    @Autowired
    public PlatformTransactionManager transactionManager(EntityManagerFactory emf){
        JpaTransactionManager txManager = new JpaTransactionManager();
        txManager.setEntityManagerFactory(emf);
        txManager.setDataSource(dataSource());
        return txManager;
    }

    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory(){
        LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
        //DATA SOURCE
        emf.setDataSource(dataSource());
        //JPA VENDOR ADAPTER
        logger.debug("About to create HibernateJpaVendorAdapter.");
        emf.setJpaVendorAdapter(jpaVendorAdapter()));
        //PACKAGES TO SCAN
        emf.setPackagesToScan("com.mycompany.myapp.domain", "com.mycompany.myapp.transformer.rule");
        //JPA PROPERTIES
        emf.setJpaProperties(jpaProperties());
        return emf;
    }

    public Properties jpaProperties() {
        Properties jpaProps = new Properties();
        jpaProps.put("hibernate.max_fetch_depth", 3);
        jpaProps.put("hibernate.jdbc_fetch_size", 50);
        jpaProps.put("hibernate.jdbc_batch_size", 10);
        jpaProps.put("hibernate.dynamic-update", "true");
        //https://hibernate.atlassian.net/browse/HHH-6962 TRYING TO AVOID HIBERNATE ERROR: HHH015010
        jpaProps.put("hibernate.exclude-unlisted-classes", "true");
        jpaProps.put("hibernate.archive.autodetection", "false");
        return jpaProps;
    }

    @Bean
    public JpaVendorAdapter jpaVendorAdapter() {
        HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
        adapter.setShowSql(true);
        adapter.setDatabasePlatform("org.hibernate.dialect.Oracle10gDialect");
        return adapter;
    }

    @Bean
    public DataSource dataSource(){
        final JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
        dsLookup.setResourceRef(true);
        DataSource dataSource = dsLookup.getDataSource("jdbc/myapp");
        return dataSource;
    }

}
M. Deinum
  • 115,695
  • 22
  • 220
  • 224
  • Couple issues: 1. `PlatformTransactionManager.setEntityManagerFactory()` does not accept a `LocalContainerEntityManagerFactoryBean` so you have to call `getObject()`. Before that happens you have to call `afterPropertiesSet()`. 2. The hibernate.archive.autodetection takes a String argument, so `false` is no good. I've tried giving it an empty string but the problem remains. I haven't found a list of valid entries for that option other than the fact that it defaults to "class,hbm" [link](http://docs.jboss.org/hibernate/entitymanager/3.5/reference/en/html/configuration.html#d0e708) – Jay Goettelmann May 21 '14 at 13:54
  • Oops, just noticed the `@Autowired` on your `transactionManager` method. So you can disregard point one. I'll give that a try. – Jay Goettelmann May 21 '14 at 14:07
  • 1
    The `EntityManagerFactory` is autowired into the method and spring takes care of calling the `afterPropertiesSet()` and `getObject()` . So no you don't need to call those methods. Regarding option 2 that is true you should pass in `"false"`. – M. Deinum May 21 '14 at 14:07
  • The valid values (for enabling) are `class` and/or `hbm` anything else disables it. If you don't specify it it defaults to `class,hbm`. So false will disable anything. – M. Deinum May 21 '14 at 14:14
  • This configuration helped me. Thanks @M.Deinum! I wonder why it is not an accepted answer. – jumping_monkey Dec 10 '19 at 09:16