Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Using Detached Criteria on two POJO classes

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

@Entity
@Table(name="flight_sectors")
public class FlightSectorVO {

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

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

@ManyToOne
@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 :

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

@Id
@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;

@ManyToOne
@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);
criteria.addOrder(Order.asc("fromStation"));
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..!
 
    Bookmark Topic Watch Topic
  • New Topic