We have a Single table inheritance with embbedid.
Hibernate 4.2.18 under JPA 2.0, JBOSS A7 complaint about having a repeated column inside the sub-class. Despite my effort, I cannot fix the problem. Could you please help me. Here is the material.
DATA_REF_CODE2_TB is a list of code.
Code:
DREFSUJID NUMBER(7,0) No
DREFCODCLE VARCHAR2(6 BYTE) No
DREFCODDESC VARCHAR2(256 BYTE) No
DATA_REF_SUJET_TB is a list of topic.
Code:
DREFSUJID NUMBER(7,0)
DREFSUJDESC VARCHAR2(128 BYTE)
Code:
@Entity
@Table(name = "DATA_REF_CODE2_TB")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "DREFSUJID", discriminatorType = DiscriminatorType.INTEGER)
public abstract class DataReferenceCode implements ICodeEntity<String> {
private static final long serialVersionUID = 1L;
@EmbeddedId
private DataReferenceCodePK id;
@NotNull
@MapsId("sujet")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "DREFSUJID", insertable = false, updatable = false)
private DataReferenceSujet sujet;
@NotNull
@Size(min = 1, max = 256)
@Column(name = "DREFCODDESC", nullable = false, length = 256, columnDefinition = "varchar2(256)")
private String description;
Code:
@Embeddable
public class DataReferenceCodePK implements Serializable {
private static final long serialVersionUID = 1L;
private long sujet;
@NotNull
@Size(min = 1, max = 6)
@Column(name = "DREFCODCLE", unique = true, insertable = false, updatable = false, nullable = false, length = 6, columnDefinition = "varchar2(6)")
private String code;
Code:
@Entity
@DiscriminatorValue("105")
public class CodeGide extends DataReferenceCode {
private static final long serialVersionUID = 1L;
// We have nothing else inside
}
Code:
public interface ICodeEntity<PK extends Serializable> extends IEntity<PK>, ICode<PK> {
}
Code:
public interface ICode<T extends Serializable> extends Serializable {
T getCode();
void setCode(T code);
String getDescription();
void setDescription(String description);
}
Code:
public interface IEntity<PK extends Serializable> extends Serializable {
// we have nothing here
}
ERROR IS
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: xxxxPU] Unable to build EntityManagerFactory
aused by: org.hibernate.MappingException:
Repeated column in mapping for entity:ca.galdes.modele.entities.CodeGode column: DREFSUJID (should be mapped with insert="false" update="false") at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:696)
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:739)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:493)
at org.hibernate.mapping.SingleTableSubclass.validate(SingleTableSubclass.java:64)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1329)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1791)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
... 35 more
I understand that error comes from the column DREFSUJID, which is defined as discriminator and also as JoinColumn to retrieve the Topic.
Adding "insertable = false, updatable = false" as no effect !?
Removing the following code remove the message but we lost the mapping with the Topic Table and moreover we got another error
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet because the embedded key 'sujet' is not the name of the field. Putting @Transient in from of 'sujet' field work.
Code:
@NotNull
@MapsId("sujet")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "DREFSUJID", insertable = false, updatable = false)
private DataReferenceSujet sujet;
Then the question, how do we keep the discriminator and at the same time the mapping of the foreign key to retrieve the topic ? .
Thank you a lot for the answer.