STATION
public class BicycleStation implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false, length = 11)
private long id;
@Column(name = "name", nullable = false)
private String name;
@Column(name = "unique_code", nullable = false)
private String unuqueCode;
@ManyToOne
@JoinColumn(name = "location_id", nullable = false)
private StationLocation locationId;
@Column(name = "address", nullable = false)
private String address;
@Column(name = "pin_code", nullable = false)
private String pinCode;
@Column(name = "created_date", nullable = false)
private Date createdDated;
@Column(name = "is_delete", nullable = false)
private boolean isDelete;
//getter and setters
}
LOCATION
public class StationLocation implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false, length = 11)
private long id;
@Column(name = "state_name", nullable = false)
private String stateName;
@Column(name = "country_name", nullable = false)
private String countryName;
@Column(name = "locality", nullable = false)
private String locality;
@Column(name = "lattitude", nullable = false)
private String lattitude;
@Column(name = "longitude", nullable = false)
private String longittude;
@Column(name = "created_date", nullable = false)
private Date createdDate;
@Column(name = "is_delete", nullable = false)
private boolean isDelete;
}
I need to find nearest station based on the query by latitude,longitude and zip code.
I'm using the below code to achieve what I need:
Session session = getSession();
List<BicycleStation> stations = session.createQuery(
"SELECT id, "+
"( 6371 * acos( cos( radians(37) ) "+
"* cos( radians( "+lattitude+" ) ) "+
"* cos( radians( "+longitude+" ) - radians(-122) ) "+
"+ sin( radians(37) ) "+
"* sin( radians( b.locationId.lattitude)))) AS distance "+
"FROM BicycleStation b "+
"HAVING distance < 25 "+
"ORDER BY distance LIMIT 0 , "+count).list();
Exception
ERROR: org.hibernate.hql.internal.ast.ErrorCounter - line 1:249: unexpected token: HAVING ERROR: org.hibernate.hql.internal.ast.ErrorCounter - line 1:249: unexpected token: HAVING line 1:249: unexpected token: HAVING
ERROR: org.hibernate.hql.internal.ast.ErrorCounter - line 1:288: unexpected token: LIMIT ERROR: org.hibernate.hql.internal.ast.ErrorCounter - line 1:288: unexpected token: LIMIT line 1:288: unexpected token: LIMIT
Aucun commentaire:
Enregistrer un commentaire