Spring NoSuchMethodError Table.indexes()hibernate-core-5.2.13.Final.jar何时尝试启动应用程序?

Spring NoSuchMethodError Table.indexes()hibernate-core-5.2.13.Final.jar何时尝试启动应用程序?,spring,jpa,websphere,Spring,Jpa,Websphere,有应用程序srping+jpa。Webserver是WebSphere8.5.13 所以,我使用WebApplicationInitializer启动应用程序,在其中添加配置 添加PerssnTeceConfig时出现问题: import org.hibernate.jpa.HibernatePersistenceProvider; import org.springframework.context.annotation.Bean; import org.springframework.con

有应用程序srping+jpa。Webserver是WebSphere8.5.13 所以,我使用WebApplicationInitializer启动应用程序,在其中添加配置

添加PerssnTeceConfig时出现问题:

import org.hibernate.jpa.HibernatePersistenceProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.annotation.Resource;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import java.util.Properties;

@Configuration
@EnableTransactionManagement
@EnableJpaAuditing
@EnableJpaRepositories(basePackages = {"persistence"})
@PropertySource("classpath:application.properties")
@ComponentScan(basePackages = {"persistence"})
public class PersistenceConfig {
    private static final String PROP_DATABASE_DRIVER = "db.driver";
    private static final String PROP_DATABASE_URL = "db.url";
    private static final String PROP_DATABASE_USERNAME = "db.username";
    private static final String PROP_DATABASE_PASSWORD = "db.password";
    private static final String PROP_HIBERNATE_DIALECT = "db.hibernate.dialect";
    private static final String PROP_HIBERNATE_SHOW_SQL = "db.hibernate.show_sql";
    private static final String PACKAGE_WITH_JPA_ENTITIES = "ru.sbrf.risks.services.data.persistence";
    private static final String PROP_HIBERNATE_HBM2DDL_AUTO = "db.hibernate.hbm2ddl.auto";
    private static final String DO_NOT_AUDIT_LOCKING_FIELD = "org.hibernate.envers.do_not_audit_optimistic_locking_field";

    @Resource
    private Environment env;

    @Bean
    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName(env.getRequiredProperty(PROP_DATABASE_DRIVER));
        dataSource.setUrl(env.getRequiredProperty(PROP_DATABASE_URL));
        dataSource.setUsername(env.getRequiredProperty(PROP_DATABASE_USERNAME));
        dataSource.setPassword(env.getRequiredProperty(PROP_DATABASE_PASSWORD));
        return dataSource;
    }

    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
        System.out.println("1");
        LocalContainerEntityManagerFactoryBean entityManager = new LocalContainerEntityManagerFactoryBean();
        System.out.println("2");
        entityManager.setDataSource(dataSource());
        System.out.println("3");
        entityManager.setPackagesToScan(PACKAGE_WITH_JPA_ENTITIES);
        System.out.println("4");
        entityManager.setPersistenceProviderClass(HibernatePersistenceProvider.class);
        System.out.println("5");
        entityManager.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
        System.out.println("6");
        entityManager.setJpaProperties(getHibernateProperties());
        System.out.println("7");
        return entityManager;
    }

    @Bean
    public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
        JpaTransactionManager transactionManager = new JpaTransactionManager();
        transactionManager.setEntityManagerFactory(entityManagerFactory);
        return transactionManager;
    }

    //Set properties hibernate
    private Properties getHibernateProperties() {
        Properties properties = new Properties();
        properties.put("hibernate.dialect", env.getRequiredProperty(PROP_HIBERNATE_DIALECT));
        properties.put("hibernate.show_sql", env.getRequiredProperty(PROP_HIBERNATE_SHOW_SQL));
        properties.put("hibernate.hbm2ddl.auto", env.getRequiredProperty(PROP_HIBERNATE_HBM2DDL_AUTO));
        properties.put("org.hibernate.envers.do_not_audit_optimistic_locking_field",
                env.getRequiredProperty(DO_NOT_AUDIT_LOCKING_FIELD));

        properties.put("verifyServerCertificate", false);
        properties.put("useSSL", false);
        properties.put("requireSSL", false);
        properties.put("useLegacyDatetimeCode", false);
        properties.put("useUnicode", "yes");
        properties.put("characterEncoding", "UTF-8");
        properties.put("serverTimezone", "UTC");
        properties.put("useJDBCCompliantTimezoneShift", true);
        return properties;
    }
}
因此,我使用hibernate-core-5.2.13.Final libriary,当尝试在WebSphere 8.5.13上启动应用程序时,我收到一条错误消息:

调用init方法失败;嵌套异常是 java.lang.NoSuchMethodError: javax/persistence/Table.indexes()[Ljavax/persistence/Index;(已加载) 从…起 文件:/opt/IBM/WebSphere/AppServer/plugins/javax.j2ee.persistence.jar 由org.eclipse.osgi.internal.baseAdapter提供。DefaultClassLoader@ec08ccb6) 从类org.hibernate.cfg.annotations.EntityBinder调用(已加载 从…起 文件:/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/installedApps/MyApp_war.ear/MyApp.war/WEB-INF/lib/hibernate-core-5.2.13.Final.jar 通过 com.ibm.ws.classloader。CompoundClassLoader@7f080f2e[war:MyApp\u war/MyApp.war]


您正试图使用一个Hibernate版本,该版本实现了与WebSphere 8.5.5中包含的JPA 2.0不同的规范版本。这是可以做到的,但您还需要带上自己的JPA API版本。要做到这一点,您需要将web模块的类装入器切换到“Parent Last”,或者将Hibernate和JPA API jar移动(s) 创建一个共享库,并将库配置为使用一个独立的类加载器(它有效地为库中的jar设置了“Parent Last”).

您正在尝试使用一个Hibernate版本,该版本实现了与WebSphere 8.5.5中包含的JPA 2.0不同的规范版本。这是可以做到的,但您还需要带上自己的JPA API版本。为此,您需要将web模块的类加载器切换到“Parent Last”或者将Hibernate和JPA API jar移动到一个共享库中,并将库配置为使用一个独立的类加载器(只为库中的jar有效地设置“Parent Last”)。

看起来像是javax.persistence的不兼容版本,而Hibernate看起来像是javax.persistence和Hibernate的不兼容版本