-->
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: referencedColumnName issue.
PostPosted: Fri Nov 28, 2008 2:15 pm 
Beginner
Beginner

Joined: Tue Dec 27, 2005 1:13 pm
Posts: 25
Location: Kingston, ON, Canada
Hibernate version: 3.2.1.GA

I have two old tables
Code:
table certificate
cert_ky bigint primaryKey

Code:
table NAME
NME_KY bigint primarykey,
nme_rlt_tbl_nm varchar,
nme_rlt_ky bigint,
NME_LST_NM varchar,
NME_GVN_NM varchar


and I have two entity class

Code:
@Entity
@Table(name="CERTIFICATE")
class Certificate {
        @Id
   @GeneratedValue
   @Column(name = "crt_ky")
   private Long certKey;

   @OneToOne(cascade = CascadeType.ALL)
   @JoinColumn(name = "crt_ky", referencedColumnName = "NME_RLT_KY")
   private Name name;
        .......
}


Code:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "NME_RLT_TBL_NM", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("certificate")
@Table(name = "NAME")
public class Name implements Serializable {

   private static final long serialVersionUID = -1060132506269104470L;

   @Id
   @GeneratedValue
   @Column(name = "NME_KY")
   private Long nameKey;
   @Column(name = "NME_GVN_NM", length = 50)
   private String givenName;
   @Column(name = "NME_LST_NM", length = 50)
   private String lastName;

   @OneToOne
   @JoinColumn(name = "NME_RLT_KY", referencedColumnName = "crt_ky", insertable = false, updatable = false)
   private Certificate certificate;
    .......
}


That means one CERTIFICATE has a NAME with NME_RLT_TBL_NM = 'certificate' and NME_RLT_KY = CERTIFICATE.CERT_KY

The problem is when I run HQL
Code:
select name from Certificate

It give me this result
Code:
select
  name1_.NME_KY as NME2_120_,
  name1_.NME_RLT_KY as NME5_120_,
  name1_.NME_GVN_NM as NME3_120_,
  name1_.NME_LST_NM as NME4_120_
from
  CERTIFICATE certificat0_
inner join
  NAME name1_
   on certificat0_.crt_ky=name1_.NME_KY


What I am expecting is

inner join
NAME name1_
on certificat0_.crt_ky=name1_.NME_RLT_KY

Why it ignore referencedColumnName = "NME_RLT_KY" in the Certificate class?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 28, 2008 2:39 pm 
Beginner
Beginner

Joined: Tue Dec 27, 2005 1:13 pm
Posts: 25
Location: Kingston, ON, Canada
I figured it out by changing Certificate with

Code:
@OneToOne(cascade = CascadeType.ALL, mappedBy="certificate")
   private Name name;


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.