Hibernate inheritance joined does't work

128 views Asked by At

I have 2 classes, first superclass second subclass:

superclass

@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;
}

subclass

@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;

this code doesn't work and i have exception

   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)

Exception pointed:

EntityManager e = Persistence.createEntityManagerFactory("footballers")
                .createEntityManager();

My persistence.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>

If i change inheritance from JOINED to SINGLE_TABLE program works good, but i want JOINED inheritance.

0

There are 0 answers