Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA inheritance Could not determine type for

Tags:

hibernate

jpa

I have a simple JPA mapping but I keep getting a Could not determine type for exception. Setters and getters are omitted.

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class SupervisionCommand {

    @Id
    @GeneratedValue
    protected Long id;

}

@Entity
public class MySupervisionCommand extends SupervisionCommand {

}

@Entity
public class Job {

    @Id
    @GeneratedValue
    private Long id;

    private SupervisionCommand command;

}

The full exception message: Could not determine type for: com.family.model.SupervisionCommand, at table: job, for columns: [org.hibernate.mapping.Column(command)]

like image 433
Sydney Avatar asked Aug 22 '13 08:08

Sydney


1 Answers

You need a OneToOne or ManyToOne annotation (depending on the actual cardinality) on command:

@ManyToOne
private SupervisionCommand command;

The default mapping for fields is @Column. And Hibernate doesn't know which type of column to use (varchar? number?) to store a SuperVisionCommand instance. If it implemented Serializable, Hibernate would serialize it and store it in a BLOB column, but this is not what you want.

like image 176
JB Nizet Avatar answered Sep 22 '22 12:09

JB Nizet