JPA spec: persisting discriminator values not mandatory? [message #768125] |
Mon, 19 December 2011 16:11 |
Karsten Wutzke Messages: 124 Registered: July 2009 |
Senior Member |
|
|
Hello all,
there's currently an issue in Hibernate 4 which I consider a bug. It is here:
https://hibernate.onjira.com/browse/HHH-4358
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:
@Entity
@Table(name = "Documents")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "discriminator", discriminatorType = DiscriminatorType.STRING)
public abstract class Document implements Serializable
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column
protected Integer id;
@Column(name = "file_name")
protected String fileName;
...
}
Here's a concrete sub class:
@Entity
@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?
Thanks
Karsten
|
|
|
Powered by
FUDForum. Page generated in 0.03327 seconds