These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]

Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Legacy Mapping Issue: @DiscriminatorColumn in an @EmbeddedId
PostPosted: Mon Oct 17, 2016 11:54 am 

Joined: Thu Jan 12, 2006 6:32 pm
Posts: 39
Location: Austin, Tx, USA, NA, Sol 3
I am working with a legacy schema that I've mapped out as follows. The problem is that the @DiscriminatorColumn annotation is a column definition on its own instead of a pointer back to an already defined column (such as @JoinColumn (which has the i/n/u=false parameters and can be set to ignore the already existing column)) and I am ending up with the error:

Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: gov.dps.dld.dls.db.domain.ApplicantHomePhone column: CTIN_CONTACT_TYP (should be mapped with insert="false" update="false"

Ancestor Entity

@DiscriminatorColumn(name = "CTIN_CONTACT_TYP", discriminatorType = DiscriminatorType.STRING, length = 2)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(catalog = "", name = "CONTACT_INFO")
public abstract class ContactInfo implements Serializable {
   private ContactInfoId id;

where the table's trinary key is:

public class ContactInfoId implements java.io.Serializable {
   private Long personId; // decimal(17), not null, [b]related key from parent table[/b]
   private ContactInfoTypeEnum contactInfoTypeEnum; // char(2), not null
   private Timestamp recordDate; // timestamp, not null
   @Column(name = "CTIN_CONTACT_TYP", insertable = true, nullable = false, updatable = false, length = FIELD_LEN_MAX_CONTACT_TYPE)
   @NotNull(message = "contactInfo.id.contactInfoTypeEnum.required")
   public ContactInfoTypeEnum getContactInfoTypeEnum() {
      return contactInfoTypeEnum;

and the three descendant classes are:

public class ApplicantEmail extends ContactInfo {
   public ApplicantEmail(){

public class ApplicantHomePhone extends ContactInfo {
   public ApplicantHomePhone() {

public class ApplicantOtherPhone extends ContactInfo {
   public ApplicantOtherPhone() {

It took me a bit to understand why this was happening but I think the biggest obstacle is the fact that the DB's discriminator is part of the PK and I'm guessing Hibernate doesn't care for that? (Rather stupid restriction since this is a very common pattern.)

At this point, the only thing I can think of to get this to work is to add an identity column which could be used as a simple @Id, moving the three fields from the compound key back to the main entity, allowing the personId field to still be used as the FK back to the Person entity, and the contactInfoTypeEnum field could still be used, but alas no.

Because of @DiscriminatorColumn wanting to ADD a column instead of referencing one, I still get the error.

Is it not possible for me to reference the discriminator column as an @Enumerated value?

Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.