-->
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: Multi-Foreign-Key mapping spread in two tables
PostPosted: Fri Oct 15, 2010 3:26 am 
Newbie

Joined: Fri Oct 15, 2010 2:31 am
Posts: 2
Hello,

could you please help me to map OneToOne relation using two-part foreing key. Unfortunatelly, one part of this key is in another table !

Table Type has two-column-primary-key TYPE_ID, PROVIDER_ID (private forein key). I need to map relation between Task and Type tables (named relationTaskType on enclosed image). To do so, I need whole PK from Type in Task. But in table Task is only half of this PK ! Second part is in linked table Client (linked by CLIENT_ID).
I do not know how to map it. Any idea? Thanks a lot.

PS: I do not like this DB design, but its old project and Iam not permited to change it )-:
IMAGE: Image http://www.rajce.net/f297352485

Code:
@Entity
@Table(name = "Task")
public class Task implements Serializable {

    @Id
    @Basic(optional = false)
    @Column(name = "TASK_ID")
    private Long taskId;

    @JoinColumn(name = "CLIENT_ID", referencedColumnName = "CLIENT_ID")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Client client;
   
   
//    @ ???
//    private Type type;   
}

@Entity
@Table(name = "TYPE")
public class Type implements Serializable {

    @EmbeddedId
    protected TypePK typePK;
   
    @JoinColumn(name = "PROVIDER_ID", referencedColumnName = "PROVIDER_ID", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Provider provider;
}

@Embeddable
public class TypePK implements Serializable {

    @Basic(optional = false)
    @Column(name = "TYPE_ID")
    private Long typeId;
   
    @Basic(optional = false)
    @Column(name = "PROVIDER_ID")
    private Long providerId;
}

@Entity
@Table(name = "CLIENT")
public class Client implements Serializable {

    @Id
    @Basic(optional = false)
    @Column(name = "CLIENT_ID")
    private Long clientId;
   
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "client", fetch = FetchType.LAZY)
    private Collection<Task> tasks;
}



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.