-->
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: Primary key which also is a foreign key
PostPosted: Wed Jul 11, 2007 11:42 am 
Newbie

Joined: Thu Dec 14, 2006 11:17 am
Posts: 9
Hello,

I'm trying to set up a primary key which also is an foreign key.

Consider the following example:

Code:
@Entity
public class Person {
  private Long personID;
 
  @Id
  public Long getPersonID() {
    return personID;
  }
  public void setPersonID(Long id) {
    this.personID = id;
  }
}


And the class where personID should be both primary and foreign key:
Code:
@Entity
public class PersonData {
  private Person person;

  @Id
  @ManyToOne
  @JoinColumn(name="personID")
  public Person getPerson() {
    return person;
  }
...
}


In the DB in table PersonData the field isn't named personID but person. It's not a foreign key, it's a simple varbinary.

What is wrong in the above code?

Thanks,
Kasperl


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 4:55 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Looks like you should be doing OneToOne and PrimaryKeyJoinColumn:
http://www.hibernate.org/hib_docs/annot ... tml#d0e998

And, you better make sure the mapping properly reflects the name and data type.

HTH,

Chris

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


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.