-->
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.  [ 2 posts ] 
Author Message
 Post subject: INHERITANCE - SINGLE TABLE - EMBEDDEDID - Repeated column
PostPosted: Mon Aug 24, 2015 5:59 am 
Newbie

Joined: Fri Dec 17, 2010 10:53 am
Posts: 8
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.


Top
 Profile  
 
 Post subject: Re: INHERITANCE - SINGLE TABLE - EMBEDDEDID - Repeated column
PostPosted: Tue Aug 25, 2015 12:43 am 
Newbie

Joined: Fri Dec 17, 2010 10:53 am
Posts: 8
We fix the problem by removing the EmbeddId key.


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

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.