简体   繁体   中英

nested exception is java.lang.NoSuchMethodError: javax/persistence/Table.indexes()[Ljavax/persistence/Index;

I am getting error

nested exception is java.lang.NoSuchMethodError: javax/persistence/Table.indexes()[Ljavax/persistence/Index;

my controller-servlet.xml file is

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing 
        infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />



    <!-- Resolves views selected for rendering by @Controllers to .jsp resources 
        in the /WEB-INF/views directory -->
    <beans:bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/jsp/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

    <beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <beans:property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
        <beans:property name="url"
            value="jdbc:oracle:thin:" />
        <beans:property name="username" value="user" />
        <beans:property name="password" value="123" />
    </beans:bean>

    <!-- Hibernate 4 SessionFactory Bean definition -->
    <beans:bean id="hibernate4AnnotatedSessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <beans:property name="dataSource" ref="dataSource" />
        <beans:property name="annotatedClasses">
            <beans:list>
                <beans:value>com.company.bmdashboard.beans.BatchJob</beans:value>
            </beans:list>
        </beans:property>
        <beans:property name="hibernateProperties">
            <beans:props>
                <beans:prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</beans:prop>
                <beans:prop key="hibernate.show_sql">true</beans:prop>
                <beans:prop key="hibernate.hbm2ddl.auto">update</beans:prop>
            </beans:props>
        </beans:property>
    </beans:bean>

    <beans:bean id="bMDashboardRepository" class="com.company.bmdashboard.repositories.BMDashboardRepositoryImpl">
        <beans:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />
    </beans:bean>
    <beans:bean id="bMDashboardService" class="com.company.bmdashboard.services.BMDashboardServiceImpl">
        <beans:property name="bMDashboardRepository" ref="bMDashboardRepository"></beans:property>
    </beans:bean>
    <context:component-scan base-package="com.company.bmdashboard" />

    <tx:annotation-driven transaction-manager="transactionManager"/>

    <beans:bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <beans:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />
    </beans:bean>

</beans:beans>

The jars file I have are

在此处输入图片说明

my RepositoryImpl is

@Repository
public class BMDashboardRepositoryImpl implements BMDashboardRepository{


    private SessionFactory sessionFactory;

    public void setSessionFactory(SessionFactory sf){
        this.sessionFactory = sf;
    }

    @Override
    public ArrayList<BatchJob> retrieveAllBatchJobs() {
        // TODO Auto-generated method stub
        System.out.println("Repository Impl: in retrieve all batch jobs");
        Session session= sessionFactory.getCurrentSession();

        @SuppressWarnings("unchecked")
        List<BatchJob> allBatchJobs=session.createQuery("From BatchJob").list();



        for(BatchJob bj:allBatchJobs)
        {
            System.out.println(bj.toString());
        }

        return (ArrayList<BatchJob>) allBatchJobs;
    }

}

When I am publishing the code in webspehre, I am getting this error. I think there is some problem with jar files?

thanks in advance

I found the work around for this.

I was using WAS 8.5 which provides its own JDK which supports JPA 2.0 . @Table.indexes() method was introduced in JPA 2.1 .

Solution for this

1)Upgrade WAS to 9

2)Instead of using @Table annotation try using xml mapping . I used ClassName.hbm.xml.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM