0
JPAプロジェクトとDerbyプロジェクトの開始に問題があります。私は次のエラーを持っている:JPA java.lang.ClassFormatError問題
Exception in thread "main" java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/Persistence
は私のMain.java
がある:
public class Main {
private static final String PERSISTENCE_UNIT_NAME = "customers";
private static EntityManagerFactory factory;
public static void main(String[] args) {
factory = Persistence.createEntityManagerFactory("todos");
EntityManager em = factory.createEntityManager();
Query q = em.createQuery("select t from CUSTOMER t");
List<Customer> customerList = q.getResultList();
for (Customer customer : customerList) {
System.out.println(customer);
}
System.out.println("Size: " + customerList.size());
em.getTransaction().begin();
Customer customer = new Customer();
customer.setCity("Warsaw");
customer.setCountry("USA");
customer.setName("John");
customer.setStreet("Street");
em.persist(customer);
em.getTransaction().commit();
em.close();
}
}
マイpersistence.xml
:
- derbyclient-:
<?xml version="1.0" encoding="UTF-8" ?> <persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"> <persistence-unit name="todos" transaction-type="RESOURCE_LOCAL"> <class>b.model.Product</class> <class>b.model.Book</class> <class>b.model.Movie</class> <class>b.model.Customer</class> <class>b.model.Order</class> <class>b.model.OrderElement</class> <properties> <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/> <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/baza;create=true" /> </properties> </persistence-unit> </persistence>
私は私のプロジェクトで2つの依存関係を持っています10.12.1.1.jar
- JavaEEの-API-6.0.jar
私が間違っているのかについての任意のアイデア?
私はこのように定義された(顧客など)すべてのモデルクラスを持っている:
@Data
@Entity(name = "CUSTOMER")
public class Customer {
@Id
@Column(name = "CUSTOMER_ID", nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO)
private long customerId;
@Column(name = "NAME")
private String name;
@Column(name = "SURNAME")
private String surname;
@Column(name = "STREET")
private String street;
@Column(name = "CITY")
private String city;
@Column(name = "ZIP_CODE")
private String zipCode;
@Column(name = "COUNTRY")
private String country;
@OneToMany(mappedBy="customer",targetEntity=Order.class, fetch= FetchType.EAGER)
private Collection orders;
}