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: Loading an Associated entity (based on fk)
PostPosted: Thu Jul 29, 2010 3:20 am 
Newbie

Joined: Wed Jul 21, 2010 10:26 pm
Posts: 10
Hi All,

I have a question related to fetching an associated entity.

There are two tables/entities.

1. Person and
2. PersonStatus

Mappings are as follows.

Person Entity:( In the table, I have a column person_status marked as a FK to Person_Status.PersonStatusID
Code:
   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "PERSON_STATUS_KEY")
   public PersonStatus getPersonStatus() {
      return this.personStatus;
   }


PersonStatus:
Code:
   private Set<Person> persons = new HashSet<Person>(0);
   @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "personStatus")
   public Set<Person> getPersons() {
      return this.persons;
   }


Problem: When I fetch the Person entity, I do not get the associated PersonStatus loaded into the person instance. Even after I call
Code:
person.getPersonStatus().


The person table has a valid FK value, I expect getPersonStatus() to load an instance of that type with the Person entity.

Could someone please point where I have gone wrong?

Thank you


Last edited by Niv on Fri Jul 30, 2010 1:33 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Loading an Associated entity (based on fk)
PostPosted: Thu Jul 29, 2010 5:47 am 
Newbie

Joined: Mon Jul 26, 2010 6:50 am
Posts: 6
Hi,

i am not an expert, but i have never used the annotations at the getters. Have you tried putting them before the properties themselves? Do you get any exception?

br


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.