2015-05-21 3 views
1

Я пытаюсь сделать приложение maven с базой данных, используя hiberntate. И одна ошибка появляется все время, когда я хочу использовать ее в графическом интерфейсе после нажатия кнопки.java.lang.NoSuchMethodError: javax.persistence.Table.indexes()

Session session = Service.getSession(); 

здесь ошибка:

Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index; 
at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:973) 
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:824) 
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3845) 
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3799) 
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1412) 
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846) 
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930) 
at models.Service.Service.<clinit>(Service.java:23) 
at GUI.Student.RegisterOnExam.getSubjects(RegisterOnExam.java:108) 

Я попытался изменить зависимости и hibernate.cfg.xml, но она по-прежнему не работает.

pom.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 

<groupId>groupId</groupId> 
<artifactId>Test</artifactId> 
<version>1.0-SNAPSHOT</version> 
<url>http://maven.apache.org</url> 
<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3.2</version> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <executions> 
       <execution> 
        <phase>install</phase> 
        <goals> 
         <goal>copy-dependencies</goal> 
        </goals> 
        <configuration> 
         <outputDirectory>${project.build.directory}/lib</outputDirectory> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <artifactId>maven-jar-plugin</artifactId> 
      <version>2.5</version> 
      <configuration> 
       <archive> 
        <manifest> 
         <addClasspath>true</addClasspath> 
         <classpathPrefix>lib/</classpathPrefix> 
         <mainClass>${mainClass}</mainClass> 
        </manifest> 
       </archive> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 
<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <mainClass>main.java.Main</mainClass> 
</properties> 
<dependencies> 

    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.8.2</version> 
     <scope>test</scope> 
    </dependency> 

    <!-- ORACLE JDBC driver, need install yourself --> 
    <dependency> 
     <groupId>postgresql</groupId> 
     <artifactId>postgresql</artifactId> 
     <version>9.1-901-1.jdbc4</version> 
    </dependency> 

    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-core</artifactId> 
     <version>4.3.7.Final</version> 
    </dependency> 

    <dependency> 
     <groupId>javassist</groupId> 
     <artifactId>javassist</artifactId> 
     <version>3.12.1.GA</version> 
    </dependency> 

    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-api</artifactId> 
     <version>1.7.5</version> 
    </dependency> 

    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-simple</artifactId> 
     <version>1.6.4</version> 
    </dependency> 

    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-log4j12</artifactId> 
     <version>1.7.5</version> 
    </dependency> 

</dependencies> 

Вот класс Service, который я использую, чтобы начать транзакцию. Я тоже как-то его тоже менял.

package models.Service; 

import org.hibernate.HibernateException; 
import org.hibernate.Session; 
import org.hibernate.SessionFactory; 
import org.hibernate.cfg.AnnotationConfiguration; 

public class Service { 
    private static final SessionFactory sessionFactory; 
    static { 

      sessionFactory = new AnnotationConfiguration() 
        .configure().buildSessionFactory(); 

    } 
    public static Session getSession() 
      throws HibernateException { 
     return sessionFactory.openSession(); 
    } 

} 

Похоже, проблема в этом, но я так не думаю. Как я могу исправить свою программу?

ответ

2

buildSessionFactory() в вашем коде устарел для версии Hibernate, которую вы используете. Вам нужно будет исправить свой код. This question объясняет больше об устаревшей фабрике сеансов.

Смежные вопросы