FireAndBlood
FireAndBlood

Reputation: 21

Hibernate Inheritance and Spring Boot

What is the proper way to have an abstract class A, inherited by abstract class B, inherited by class C using Hibernate and Spring Boot?

@Entity 
@Inheritance 
abstract class A{} 

@Entity
@Inheritance
abstract class B extends A{}

@Entity 
@Inheritance 
final class C entends B{} 

The problem is I have an exception "Caused by: org.postgresql.util.PSQLException: ERROR: column something(from class A) does not exist". Are my annotations wrong?

Upvotes: 0

Views: 281

Answers (1)

Eliaquim Tchitalacumbi
Eliaquim Tchitalacumbi

Reputation: 396

As far as I know, the abstract class should not be an Entity. You cannot instanciate it. Try

@MappedSuperclass
public abstract class A {
}
@MappedSuperclass
public abstract class B extends A {
}
@Entity
public class C extends B {
}

And, like he said, class C should not be final.

Upvotes: 1

Related Questions