codebot
codebot

Reputation: 2646

Java play Ebean finder returns wrong data for greater than query

I have 2 tables named Ride and Ride Location.

Ride.java

@Entity
public class Ride extends Model {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long rideId;

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss z")
    private Date rideDate;

    @OneToMany(mappedBy = "ride", cascade = CascadeType.ALL)
    private List<RideLocation> rideLocations;
}

RideLocation.java

@Entity
public class RideLocation extends Model {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long rideLocationId;
    private String locationName;
    private float lat;
    private float lon;

    @JsonBackReference
    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private Ride ride;
}

I'm trying to fetch all rides which is rideDate is greater than or equal to a given date and 'locationName' is equal to given location.

List<RideLocation> list = Ebean.find(RideLocation.class).where().ge("ride.rideDate", "2017-09-13").and().like("locationName", "San Jose").findList();

This returns data equals to `locationName'. Even if it's a date less than the given date, this returns data. How may I fix this?

Upvotes: 0

Views: 629

Answers (1)

MrMisery
MrMisery

Reputation: 416

You are simply trying to deal with the date as a string , with will not give you the result you desire. try either converting the string to a date or you can also compare timestamps (depends on how you are storing it in your database).

Upvotes: 1

Related Questions