-->
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.  [ 3 posts ] 
Author Message
 Post subject: Compound primary keys and OneToOne mapping - need advice
PostPosted: Mon Apr 26, 2010 2:10 am 
Newbie

Joined: Sun Apr 25, 2010 10:23 am
Posts: 6
Hi,

I have three entities A, B, and C.

Code:
@Entity
public class A implements java.io.Serializable {

    @Id
    private String s;
    ...
}

@IdClass(BKey.class)
@Entity
public class B implements java.io.Serializable {

    @Id   
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date pDate;
   
    @Id   
    @ManyToOne
    private A a;

    @Id
    protected int cInt;
    ...
}

@IdClass(CKey.class)
@Entity
public class C implements java.io.Serializable {

    @Id   
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date pDate;
   
    @Id   
    @ManyToOne
    private A a;
    ...
}


I want to introduce OneToOne unidirectional read-only relationship with source being B and target being C. How would I do that?

I tried declaring C field in B as follows:

Code:
@OneToOne
@JoinColumns({
     @JoinColumn(name="A_S",referencedColumnName="A_S",insertable=false,updatable=false),
     @JoinColumn(name="PDATE",referencedColumnName="PDATE",insertable=false,updatable=false)})
protected C c;


However, every query to load B leaves field C as null. What am I doing wrong?

Thank you!


Top
 Profile  
 
 Post subject: Re: Compound primary keys and OneToOne mapping - need advice
PostPosted: Mon Apr 26, 2010 7:56 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Looks like it could work in theory. Which version of Hibernate are you playing with?
And what are your true mappings? From what you describe, there is a mismatch between your column names and your mapping.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Compound primary keys and OneToOne mapping - need advice
PostPosted: Mon Apr 26, 2010 11:03 am 
Newbie

Joined: Sun Apr 25, 2010 10:23 am
Posts: 6
Thanks Emmanuel. It was just a simple mistype of column name. Works perfectly.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.