Java.lang错误?

伙计们我想读取一个Excel文件,并将信息保存到数据库在spring的应用程序,但我面临着这个错误。 下面是我的工作! (我没有分享我的控制器等,我只是需要保存他们的数据库后,我会spring工作。

主要的春季应用

package com.javainuse; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.AnnotationConfiguration; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class SpringBootHelloWorldApplication { public static void main(String[] args) throws IOException { System.out.println("Debug Print"); Read(); SpringApplication.run(SpringBootHelloWorldApplication.class, args); } private static void Read() throws IOException { System.out.println("Debug print"); SessionFactory sf = new AnnotationConfiguration().configure("hibernate.cfg.xml").buildSessionFactory(); Session session = sf.openSession(); FileInputStream file = new FileInputStream(new File("C:/Users/MONSTER/Desktop/Hello.xlsx")); XSSFWorkbook workbook = new XSSFWorkbook(file); XSSFSheet sheet = workbook.getSheetAt(0); Row row; for(int i=1; i<=sheet.getLastRowNum(); i++){ row = (Row) sheet.getRow(i); //sheet number String id; if( row.getCell(0)==null) { id = "0"; } else id= row.getCell(0).toString(); String name; if( row.getCell(1)==null) { name = "null";} else name = row.getCell(1).toString(); //else copies cell data to name variable String phone; if( row.getCell(2)==null) { phone = "null"; } else phone = row.getCell(2).toString(); Transaction t = session.beginTransaction(); Customer std = new Customer(); std.setId((int) Double.parseDouble(id)); std.setName(name); std.setPhone(phone); System.out.println(std.getId()+" "+std.getName()+" "+std.getPhone()); session.saveOrUpdate(std); t.commit(); } file.close(); System.out.println("Completed!"); } } 

我正在尝试读取excel并在春季开始之前保存数据。

我的客户类

 package com.javainuse; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name="customer", schema="excel") public class Customer { @Id // @GeneratedValue(strategy = GenerationType.AUTO) private int id; @Column private String name; @Column private String phone; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } public Customer(int id, String name, String phone) { super(); this.id = id; this.name = name; this.phone = phone; } public Customer() { super(); } } 

的hibernate.cfg.xml

 <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/excel</property> <property name="connection.username">root</property> <property name="connection.password"></property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hbm2ddl.auto">update</property> <property name="show_sql">true</property> <mapping class="com.javainuse.Customer"/> </session-factory> </hibernate-configuration> 

错误

 Exception in thread "main" 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 com.javainuse.SpringBootHelloWorldApplication.Read(SpringBootHelloWorldApplication.java:31) at com.javainuse.SpringBootHelloWorldApplication.main(SpringBootHelloWorldApplication.java:22) 14:05:19.071 [pool-1-thread-1] DEBUG org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl - Connection pool now considered primed; min-size will be maintained 

谢谢!

尝试下面的解决scheme。

更新hibernateJPA到2.1和它的工作。

 <dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.1-api</artifactId> <version>1.0.0.Final</version> </dependency> 

看起来像它的一个hibernate持久性版本问题…只是更新您的持久性库..它应该解决这个错误