Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Using Detached Criteria on two POJO classes

Nitin Menon
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem using criteria. I have 2 VO classes. The first one is

public class FlightSectorVO {

@Id @GeneratedValue
@Column(name = "sector_id")
private long sectorId;

@JoinColumn(name = "from_station")
private StationVO fromStation;

@JoinColumn(name = "to_station")
private StationVO toStation;

@Column(name = "first_class")
private byte firstClass;

@Column(name = "descr")
private String description;

@Column(name = "active")
private int active;
getters and setters come here...


The second VO class is :

@Table(name = "station")
public class StationVO implements Serializable{
private static final long serialVersionUID = 1L;

@Column(name = "station_code")
@Pattern(regex = "[A-Za-z][A-Za-z][A-Za-z]", message = "Invalid station code. Invalid characters found")
private String stationCode;

@Column(name = "station_label")
@NotEmpty(message = "Station is required")
@Pattern(regex = "[A-Za-z0-9\\s_-]*", message = "Invalid station. Invalid characters found")
@Length(max = 50, message = "Station cannot be more than 50 characters")
private String station;

@Column(name = "station_desc")
private String stationDescr;

@JoinColumn(name = "country_code")
private CountryVO countryCode;

@Column(name = "active")
private int active = -1;

I have to print the contents of FlightSectorVO order by fromStation, station( of StationVO) in ascending order. in DB, the from_station is a foreign key to the station_code field in station table and holds the value inside station_code of station table. However, I have to display the contents of flight_sector order by station from_ station (station_label in db).

In my DAO class I gave :

DetachedCriteria criteria = DetachedCriteria .forClass(FlightSectorVO.class);
Its displaying in the order of station code. How do i display the value of FlightSectorVO order by fromStation alphabetically in order by station.

Thank you in advance..!
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!