@dsafdsafsdfsdafdsf

Почему Spring Data JDBC не создает сущность?

Создаю проект по книге "Spring in action". Там рекомендуют использовать Application Runner для того, чтобы вставлять постоянные данные в бд H2 при запуске приложения.
Как я это сделал:
import me.learning.tacocloud.data.IngredientRepository;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ApplicationConfig {
    @Bean
    public ApplicationRunner dataLoader(IngredientRepository repo) {
        return args -> {
            repo.save(new Ingredient("FLTO", "Flour Tortilla", Ingredient.Type.WRAP));
            repo.save(new Ingredient("COTO", "Corn Tortilla", Ingredient.Type.WRAP));
            repo.save(new Ingredient("GRBF", "Ground Beef", Ingredient.Type.PROTEIN));
            repo.save(new Ingredient("CARN", "Carnitas", Ingredient.Type.PROTEIN));
            repo.save(new Ingredient("TMTO", "Diced Tomatoes", Ingredient.Type.VEGGIES));
            repo.save(new Ingredient("LETC", "Lettuce", Ingredient.Type.VEGGIES));
            repo.save(new Ingredient("CHED", "Cheddar", Ingredient.Type.CHEESE));
            repo.save(new Ingredient("JACK", "Monterrey Jack", Ingredient.Type.CHEESE));
            repo.save(new Ingredient("SLSA", "Salsa", Ingredient.Type.SAUCE));
            repo.save(new Ingredient("SRCR", "Sour Cream", Ingredient.Type.SAUCE));
        };
    }
}

IngredientRepository - это CrudRepository
Какую ошибку я получаю:
Caused by: org.springframework.dao.IncorrectUpdateSemanticsDataAccessException: Failed to update entity [Ingredient(id=FLTO, name=Flour Tortilla, type=WRAP)]. Id [FLTO] not found in database.
	at org.springframework.data.jdbc.core.JdbcAggregateChangeExecutionContext.updateWithoutVersion(JdbcAggregateChangeExecutionContext.java:316) ~[spring-data-jdbc-2.4.0.jar:2.4.0]
	at org.springframework.data.jdbc.core.JdbcAggregateChangeExecutionContext.executeUpdateRoot(JdbcAggregateChangeExecutionContext.java:109) ~[spring-data-jdbc-2.4.0.jar:2.4.0]
	at org.springframework.data.jdbc.core.AggregateChangeExecutor.execute(AggregateChangeExecutor.java:71) ~[spring-data-jdbc-2.4.0.jar:2.4.0]
	... 43 common frames omitted

Что я делаю не так?
  • Вопрос задан
  • 419 просмотров
Пригласить эксперта
Ответы на вопрос 1
@walfer2020
Начинающий программист
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы