I am using hibernate in spring boot and have a super class person and a subclass driver and and multiple embedded objects (composition) inside person and driver and I am trying to make a driver table that extends from super class person, but when I run the program I have the following error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.ClassCastException: org.hibernate.mapping.SingleTableSubclass cannot be cast to org.hibernate.mapping.RootClass
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078) ~[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857) ~[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]...
here is my Driver class:
@Entity
public class Driver extends Person {
@Column(name = "workingStatus")
private String workingStatus;
@Column(name = "company")
private String company;
@Column(name = "rate")
private int rate;
@Embedded
private DrivingLicense drivingLicense;
@Embedded
private Vehicle vehicle;
@Embedded
private Order order;
public Driver() {
}
//setters and getters
}
Person Class:
@Entity
@Inheritance
@Table(name = "person")
public abstract class Person {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(name = "nickName")
private String nickName;
@Column(name = "username")
private String username;
@Column(name = "password")
private String password;
@NotNull(message = "can't be empty")
@Column(name = "mobileNumber")
private String mobileNumber;
@Email
@Pattern(regexp = "[A-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,3}$", message = "wrong e-mail")
@Column(name = "email")
private String email;
@Column(name = "profilePicturePath")
private String profilePicturePath;
@Embedded
private Address address;
@NotNull
@Valid
@Embedded
private IDCard idCard;
//setters and getters
}
I am using MySQL database with spring boot hibernate, Can anyone help me to determine the problem and how to fix it