Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieving Collection

 
Ananth Ram
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a domain object(profile) holding array of different objects as below.

profile have school[], experience[], etc.

I want to retrieve only school[].

Could some one help on the same.

Thanks,

Ananth
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
Ananth Ram
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried declaring an arraylist and tried to populate the data from education[] from profile object.

Could someone give me some tip on retrieving the same.

Thanks in advance,

Ananth
 
Adam Schaible
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to provide more detail before anyone can understand your question. Give us some information on how the data is related, what code you created to retrieve, what "didn't work" about it, etc - then you'll probably get some good responses.
 
Ananth Ram
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public Profile getProfile(String userName) {
Profile profile = new Profile();
School[] school = null;
Experience[] experience = null;

String query = "SELECT ...";
stmt.execute(query);
if(ra.next()){
experience = getExperience(person.getPersonId());
school = getSchool(person.getPersonId());
user.setSchool(school);
user.setExperience(experience);
}
return profile;


I am able to have profile loaded with school[] and experience[] data. I need to get only school[] from profile.

Please advise.

Thanks,
Ananth
 
Adam Schaible
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So according to the following:



there is a method on Profile that returns the schools for a given personId - judging by this code, it looks like you have a reference to person, or something does - I'd find that reference, and then run the code listed above.
 
Ananth Ram
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, got it.
 
Ananth Ram
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I tried but still I am not able to get the schoolname from School.

The following classes are created.

public Profile getProfile(String userName) {
Profile profile = new Profile();
School[] school = null;

String query = "SELECT ...";
stmt.execute(query);
if(rs.next()){
school = getSchool(person.getPersonId());
profile.setSchool(school);
}
return profile;
}

The Profile/School/Person class are

// School.java
package domain;

public class School implements Serializable {

private int schoolId;
private String schoolName;
private int degreeId;
private String degreeName;
private int personId;

//getter / setter methods

public School populate(ResultSet rs) throws Exception {
this.setSchoolId(rs.getInt("schoolid"));
this.setPersonId(rs.getInt("personid"));
this.setSchoolName(rs.getString("schoolname"));
return this;
}
}

// Profile.java
package domain;
public class Profile {

private AccessInfo accessInfo;
private Person person;
private School[] school;
// getter/setter methods.
}

// Person.java
package domain;
import java.io.Serializable;
import java.sql.ResultSet;
import java.util.*;
public class Person implements Serializable {
private Integer personId;
private String firstName;
private String lastName;
private String accessInfoId;
private long companyId;
}

Now,

I am trying to retrieve the schoolName from School[]

School[] testSchool = null;

testSchool = dBean.getProfile(personId).getSchool();


I am able to see the data in testSchool, and I want to dynamically populate the schoolname for a personId.

testSchool.length = 2.

Could some one tell me what should be the next step.

Thanks
 
Ananth Ram
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could some one help me on the same.

Thanks in advance.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic