|JPA spec: persisting discriminator values not mandatory? [message #768125]
||Mon, 19 December 2011 11:11
| Karsten Wutzke
Registered: July 2009
there's currently an issue in Hibernate 4 which I consider a bug. It is here:
You don't necessarily have to read everything up front. The short story is that Hibernate doesn't persist discriminator values of entities involved in inheritance with an @DiscriminatorColumn.
I have a webapp to manage a number of documents (upload, delete, ...), which got mapped as this base class:
@Table(name = "Documents")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "discriminator", discriminatorType = DiscriminatorType.STRING)
public abstract class Document implements Serializable
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Integer id;
@Column(name = "file_name")
protected String fileName;
Here's a concrete sub class:
@Table(name = "ExternalDocuments")
@DiscriminatorValue(value = "external")
public class ExternalDocument extends SystemDocument
... // no additional fields
Any new ExternalDocument instance gets the column's default string value in the database, here 'official' (or the first value in the list of a MySQL ENUM('official', 'reference', 'curriculumvitae', 'individual', 'external')) - which is incorrect. (AFAIK EclipseLink doesn't do this!)
I cannot find anything in the JPA 2 spec about whether discriminator values have to be persisted or not. Ultimately the person I discuss the issue with in the bug report might be correct that this Hibernate JPA issue doesn't need to be fixed.
Is this true or is it just missing information in the JPA spec? If it is present, where can I find it?