Привет, я пытаюсь выполнить собственный SQL-запрос на MySQL из спящего режима.Raw sql ниже работает нормально с терминалом
select (6371 * ACOS(COS(RADIANS(my_latitude)) * COS(RADIANS(a.latitude)) * COS(RADIANS(a.longitude) - RADIANS(my_longitude)) + SIN(RADIANS(my_latitude)) * SIN(RADIANS(a.latitude)))) AS distance FROM address a HAVING distance < 5 ORDER BY distance
Но когда я использую его с хранилищем, я получаю исключение
org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing column [q] in table [address]
Мой адрес объекта, как показано ниже:
@Entity
@Table(name = "address")
public class Address extends Auditable<String> {
@Getter
@Setter
private Double latitude;
@Setter
@Getter
private Double longitude;
@Setter
@Getter
private String address;
@Getter
@Setter
@ManyToOne
@JoinColumn(name = "user_id")
@JsonManagedReference
private User user;
}
Мой NearByDto, как показано ниже:
public interface NearByDto {
Long getId();
String getAddress();
Double getDistance();
}
Репозиторий выглядит следующим образом:
@Repository
public interface AddressRepository extends JpaRepository<Address, Long> {
@Query(value = "select (6371 * ACOS(COS(RADIANS(my_latitude)) * COS(RADIANS(a.latitude)) * COS(RADIANS(a.longitude) - RADIANS(my_longitude)) + SIN(RADIANS(my_latitude)) * SIN(RADIANS(a.latitude)))) AS distance FROM address a HAVING distance < 5 ORDER BY distance", nativeQuery = true)
List<NearByDto> findNearby();
}
Auditable
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@NoArgsConstructor
public abstract class Auditable<U> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Getter
@Setter
private Long id;
@CreatedBy
@Getter
@Setter
@JsonIgnore
protected U createdBy;
@Getter
@Setter
@CreatedDate
@Temporal(TIMESTAMP)
@JsonIgnore
protected Date creationDate;
@Getter
@Setter
@LastModifiedBy
@JsonIgnore
protected U lastModifiedBy;
@Getter
@Setter
@LastModifiedDate
@Temporal(TIMESTAMP)
@JsonIgnore
protected Date lastModifiedDate;
@Getter
@Setter
@JsonIgnore
protected Boolean isActive;
}
Класс пользователя
@Entity
@Table(name = "users")
public class User extends Auditable<String> implements UserDetails {
....
@Getter
@Setter
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JsonBackReference
private Set<Address> addresses;
....
}
* Для справки
my_latitude = широта в строке запроса
my_longitude = hardcoded_longitude в строке запроса