Not sure if I worded the question correctly but i'm working with a postgres database

I'm looking for the equivalent of the following sql statement.

Select \* from track where id in (Select track\_id from track\_item where item\_time between x and y). 

I'm new to hibernate and i've tried doing this using a Hibernate Query and using Criteria and failed both ways. 

If there is an awnser using both methods it would be nice to see both examples as I'm trying to learn how to use both.

This is the create table information for the two tables

```
CREATE TABLE track (
id bigint NOT NULL,
track_uuid text,
track_number text,
track_exercise_indicator_id bigint NOT NULL,
track_simulation_indicator_id bigint NOT NULL,
track_status_id bigint,
last_modified timestamp with time zone DEFAULT timezone('utc'::text, now())
);

CREATE TABLE track_item (
id bigint NOT NULL,
track_item_type_id bigint NOT NULL,
item_time bigint NOT NULL,
frame_number bigint,
image_source text,
last_modified timestamp with time zone DEFAULT timezone('utc'::text, now()),
track_item_uuid character varying(200) NOT NULL,
track_id bigint NOT NULL
);

ALTER TABLE ONLY track_item
ADD CONSTRAINT track_item_track_id_fkey FOREIGN KEY (track_id) REFERENCES track(id);

ALTER TABLE ONLY track_item
ADD CONSTRAINT track_item_track_item_type_id_fkey FOREIGN KEY (track_item_type_id) REFERENCES track_item_type(id);

```

The java classes generated from the above table are.

```
@Entity
@Table(name = "track", schema = "d2d")
public class Track implements java.io.Serializable {

/**
 * ID.
 */
private static final long serialVersionUID = 2313376497269789747L;
private long id;
private TrackSimulationIndicator trackSimulationIndicator;
private TrackStatus trackStatus;
private TrackExerciseIndicator trackExerciseIndicator;
private String trackUuid;
private String trackNumber;
private Date lastModified;
private Set<TrackMessageToTrackMapping> trackMessageToTrackMappings = new HashSet<TrackMessageToTrackMapping>(
        0);
private Set<TrackInterval> trackIntervals = new HashSet<TrackInterval>(0);
private Set<AnomalyToTrackMapping> anomalyToTrackMappings = new HashSet<AnomalyToTrackMapping>(
        0);
}

 @Entity
 @Table(name = "track_item", schema = "d2d")
 public class TrackItem implements java.io.Serializable {

/**
 * ID.
 */
private static final long serialVersionUID = 8469898950069782997L;
private long id;
private TrackItemType trackItemType;
private long itemTime;
private Long frameNumber;
private String imageSource;
private String trackItemUUID;
private Track track;
private Date lastModified;
private Set<TrackPoint> trackPoints = new HashSet<TrackPoint>(0);
private Set<TrackInformation> trackInformations = new HashSet<TrackInformation>(
        0);
}

```