У меня есть 2 класса, первый суперкласс, второй подкласс:
суперкласс
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Person {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
protected long id;
@Column(name = "firstname", nullable = false)
@NotNull
protected String firstname;
@Column(name = "lastname", nullable = false)
@NotNull
protected String lastname;
}
подкласс
@Entity
@Table(name = "referee")
public class Referee extends Person {
@Column(name = "LicenceNumber", nullable = false)
@NotNull
@Size(min = 10, max = 10)
private String licenceNumber;
@Column(name = "rate", nullable = false)
@NotNull
private int rate;
этот код не работает, и у меня есть исключение
Exception in thread "main" java.lang.ExceptionInInitializerError
at sample.Main.main(Main.java:27)
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named footballers
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at sample.Main.main(Main.java:31)
Указано исключение:
EntityManager e = Persistence.createEntityManagerFactory("footballers")
.createEntityManager();
Моя настойчивость. Xml
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/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">
<persistence-unit name="footballers">
<description>JPA Demo</description>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name = "hibernate.validator.apply_to_ddl property" value="false"/>
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/footballers?profileSQL=false"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="root"/>
</properties>
</persistence-unit>
</persistence>
Если я изменю наследование с JOINED на SINGLE_TABLE, программа работает хорошо, но я хочу наследование JOINED.