-->
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: @ManyToOne inside the composite Id
PostPosted: Fri Jul 27, 2007 4:40 pm 
Newbie

Joined: Fri Jul 27, 2007 4:24 pm
Posts: 5
Hibernate version: 3

Hi,

Code:
@Entity
public class Person implements Serializable {

  private long uid;
  // ...

  @Id
  public long getUid() {
    return uid;
  }

  public void setUid(long uid) {
    this.uid = uid;
  }

  // ...
}

@Entity
@IdClass(PersonInfoId.class)
public class PersonInfo implements Serializable {
 
  private Person person;
  private String fieldName;
  private String value;

  @Id
  @ManyToOne
  public Person getPerson() {
    return person;
  }

  public void setPerson(Person person) {
    this.person= person;
  }

  @Id
  public String getFieldName() {
    return fieldName;
  }

  public void setFieldName(String fieldName) {
    this.fieldName= fieldName;
  }
 
  //...
}

@Embeddable
public class PersonInfoId implements Serializable {
 
  private Person person;
  private String fieldName;

  public Person getPerson() {
    return person;
  }

  public void setPerson(Person person) {
    this.person= person;
  }

  public String getFieldName() {
    return fieldName;
  }

  public void setFieldName(String fieldName) {
    this.fieldName= fieldName;
  }
 
  // override equals/hashCode
}


When I'm trying to query:
from PersonInfo pi where pi.person.uid = :uid

I get an error saying that property uid in PersonInfo cannot be found.

Am I doing something wrong with mappings?

Thanks,

P.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 28, 2007 6:42 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
You need to define the ManyToOne relationship to Person in the ID class, not in PersonInfo:

Code:
@Embeddable
public class PersonInfoId implements Serializable {
 
  private Person person;
  private String fieldName;

// HERE ---------------
  @ManyToOne
  public Person getPerson() {
    return person;
  }
...


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.