i have a class with two OneToMany relations pointing to different leafs of a class hierarchy mapped to a single table.
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "personId")
private List<Book> books = new ArrayList<Book>();
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "personId")
private List<FavoriteBook> favoriteBooks = new ArrayList<FavoriteBook>();
both classes Book and FavoriteBook inherit from AbstractBook which defines a SingleTableInheritance:
@Entity
@Table(name = "ST_BOOK", uniqueConstraints = { @UniqueConstraint(columnNames = { "author", "name" }) })
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class AbstractBook {
When i load a person and access the relationships, Hibernate does not include the discriminator in the select and ends up with the following exception:
As a workaround i could a a Hibernate-specific annotation to the Root of my Class hierarchy, but i'd prefer to stick to JPA-Annotations.
import org.hibernate.annotations.DiscriminatorOptions;
@Entity
@Table(name = "ST_BOOK", uniqueConstraints = { @UniqueConstraint(columnNames = { "author", "name" }) })
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorOptions(force = true) public abstract class AbstractBook {
there's another (quite old) issue about WrongClassException https://hibernate.atlassian.net/browse/HHH-5954 but without OneToManyRelations.
|