inheritance - Hibernate not inserting DTYPE - value is null -


i have following classes:

@entity @table( name="user" ) @inheritance( strategy = inheritancetype.joined ) public abstract class user implements serializable {   private static final long serialversionuid = 1l;    @id   @generatedvalue( strategy = generationtype.identity )   @column( name = "id" )   private long id;    @column( name = "email_address" )   private string emailaddress;    /* getters , setters not shown */ } 

and

@entity @table( name="admin" ) public class admin extends user implements serializable {   private static final long serialversionuid = 1l;    @column( name = "role" )   private string role;    /* getters , setters not shown */ } 

i expect hibernate use default column dtype varchar(31) exists in user table. when code tries persist new admin object see following logged console:

hibernate: insert user (email_address) values (?) hibernate: insert admin (role) values (?)  

thus no attempt made hibernate set user.dtype column, , remains null in database. expected set admin.

what doing wrong? have tried explicitly setting @discriminatorcolumn on user class , @discriminatorvalue on admin class (and tried adding user well) no avail.

a discriminator column not needed when using inheritancetype.joined, , based on this bug report, apparently doesn't work hibernate annotations.

in comment, "because no user object can instantiated directly, there no need type discriminator, since type known ahead of time." , that's sort of right. main point joined inheritance, type of retrieved db figured out based on table came , doesn't have stored in column.

there appears confusion , debate whether discriminator columns should supported, , in fact bug noted above rejected, hibernate team decided shouldn't supported.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -