Программисты JAVA общаются здесь
Anonymous
Строка была обновлена или удалена другой транзакцией (или картирование неспасенного значения было неверным): [com.exam
Сообщение
Anonymous » 29 янв 2025, 21:42
Я читаю книгу «Спринг-бут и бег». И у меня есть следующая проблема, я не понимаю, как ее решить. -Поляры было неверно): [com.example.mysqlplanefinder.models.aircraft#34]
P>aircraft.java
Код: Выделить всё
package com.example.mysqlplanefinder.models;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import java.time.Instant;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Aircraft {
@Id
@GeneratedValue
private Long id;
private String callsign, squawk, reg, flightno, route, type, category;
private int altitude, heading, speed;
@JsonProperty("vert_rate")
private int vertRate;
@JsonProperty("selected_altitude")
private int selectedAltitude;
private double lat, lon, barometer;
@JsonProperty("polar_distance")
private double polarDistance;
@JsonProperty("polar_bearing")
private double polarBearing;
@JsonProperty("is_adsb")
private boolean isADSB;
@JsonProperty("is_on_ground")
private boolean isOnGround;
@JsonProperty("last_seen_time")
private Instant lastSeenTime;
@JsonProperty("pos_update_time")
private Instant posUpdateTime;
@JsonProperty("bds40_seen_time")
private Instant bds40SeenTime;
}
< /code>
listcraftrepository.java
package com.example.mysqlplanefinder.repositories;
import com.example.mysqlplanefinder.models.Aircraft;
import org.springframework.data.repository.CrudRepository;
public interface AircraftRepository extends CrudRepository { }
< /code>
planepoller.java
package com.example.mysqlplanefinder;
import com.example.mysqlplanefinder.models.Aircraft;
import com.example.mysqlplanefinder.repositories.AircraftRepository;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
@EnableScheduling
@Component
@RequiredArgsConstructor
class PlanePoller {
@NonNull
private final AircraftRepository repository;
private WebClient client =
WebClient.create("http://localhost:7634/aircraft");
@Scheduled(fixedRate = 1000)
private void pollPlanes() {
repository.deleteAll();
client.get()
.retrieve()
.bodyToFlux(Aircraft.class)
.filter(plane -> !plane.getReg().isEmpty())
.toStream()
.forEach(repository::save);
repository.findAll().forEach(System.out::println);
}
}
Я пытался удалить метод .deleteall () и добавить версии, как был рекомендован AI, но ничего не помогло.
Подробнее здесь:
https://stackoverflow.com/questions/793 ... apping-was
1738176121
Anonymous
Я читаю книгу «Спринг-бут и бег». И у меня есть следующая проблема, я не понимаю, как ее решить. -Поляры было неверно): [com.example.mysqlplanefinder.models.aircraft#34] P>aircraft.java [code]package com.example.mysqlplanefinder.models; import com.fasterxml.jackson.annotation.JsonProperty; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import java.time.Instant; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @Entity @Data @NoArgsConstructor @AllArgsConstructor public class Aircraft { @Id @GeneratedValue private Long id; private String callsign, squawk, reg, flightno, route, type, category; private int altitude, heading, speed; @JsonProperty("vert_rate") private int vertRate; @JsonProperty("selected_altitude") private int selectedAltitude; private double lat, lon, barometer; @JsonProperty("polar_distance") private double polarDistance; @JsonProperty("polar_bearing") private double polarBearing; @JsonProperty("is_adsb") private boolean isADSB; @JsonProperty("is_on_ground") private boolean isOnGround; @JsonProperty("last_seen_time") private Instant lastSeenTime; @JsonProperty("pos_update_time") private Instant posUpdateTime; @JsonProperty("bds40_seen_time") private Instant bds40SeenTime; } < /code> listcraftrepository.java package com.example.mysqlplanefinder.repositories; import com.example.mysqlplanefinder.models.Aircraft; import org.springframework.data.repository.CrudRepository; public interface AircraftRepository extends CrudRepository { } < /code> planepoller.java package com.example.mysqlplanefinder; import com.example.mysqlplanefinder.models.Aircraft; import com.example.mysqlplanefinder.repositories.AircraftRepository; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.client.WebClient; @EnableScheduling @Component @RequiredArgsConstructor class PlanePoller { @NonNull private final AircraftRepository repository; private WebClient client = WebClient.create("http://localhost:7634/aircraft"); @Scheduled(fixedRate = 1000) private void pollPlanes() { repository.deleteAll(); client.get() .retrieve() .bodyToFlux(Aircraft.class) .filter(plane -> !plane.getReg().isEmpty()) .toStream() .forEach(repository::save); repository.findAll().forEach(System.out::println); } } [/code] Я пытался удалить метод .deleteall () и добавить версии, как был рекомендован AI, но ничего не помогло. Подробнее здесь: [url]https://stackoverflow.com/questions/79340618/row-was-updated-or-deleted-by-another-transaction-or-unsaved-value-mapping-was[/url]