-->
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: Composite FK and Composite ID share some columns
PostPosted: Thu Nov 12, 2009 9:30 am 
Newbie

Joined: Tue Sep 18, 2007 11:24 am
Posts: 9
Hi,

I don't know how to map the following (legacy) situation:

Tables:
SUBSYSTEM(SS_CODE, VERSION)
EQUIPMENT(EQ_CODE, VERSION, SS_CODE)

there is a FK from EQUIPMENT(SS_CODE,VERSION) to SUBSYSTEM(SS_CODE, VERSION)

so in Equipment, the "version" column is used in the PK and in the relation.

Here is my initial mapping:

Code:
public class Subsystem {
   @EmbeddedId
    private SubsystemId compositeId;

    @Embeddable
    public static class SubsystemId implements Serializable {
        @Column(name="SS_CODE")
        private String code;

        @Column(name="VERSION")
        private Integer version;
    }
}

public class Equipment {
   @EmbeddedId
    private EquipmentId compositeId;

    @ManyToOne
    @JoinColumns({
       @JoinColumn(name="SS_CODE", referencedColumnName="SS_CODE"),
       @JoinColumn(name="VERSION", referencedColumnName="VERSION")
    })
    private Subsystem subsystem;

    @Embeddable
    public static class EquipementId implements Serializable {
        @Column(name="EQ_CODE")
        private String code;

        @Column(name="VERSION")
        private Integer version;
    }
}


I get the following exception:
Quote:
org.hibernate.MappingException: Repeated column in mapping for entity: Equipment column: VERSION (should be mapped with insert="false" update="false")


So I tried the given advice:

Code:
    @ManyToOne
    @JoinColumns({
       @JoinColumn(name="SS_CODE", referencedColumnName="SS_CODE"),
       @JoinColumn(name="VERSION", referencedColumnName="VERSION", insertable=false, updatable=false)
    })
    private Subsystem subsystem;


But now I get the following error:
Quote:
org.hibernate.AnnotationException: Mixing insertable and non insertable columns in a property is not allowed: Equipmentsubsystem


Do you have any suggestion on how to tell hibernate to reuse columns already mapped in the composite Id?

I'm using Hibernate 3.5.0-Beta-2.

Thanks

Julien


Top
 Profile  
 
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.