Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'movieRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract boolean no.kristiania.soj.groupexam.movie.MovieRepositoryCustom.update(long,java.lang.String,java.lang.String,java.lang.String,java.lang.String,int,java.time.ZonedDateTime)! No property update found for type MovieEntity!
Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract boolean no.kristiania.soj.groupexam.movie.MovieRepositoryCustom.update(long,java.lang.String,java.lang.String,java.lang.String,java.lang.String,int,java.time.ZonedDateTime)! No property update found for type MovieEntity!
Я делаю грубое репо для фильма, и я не могу понять, почему он постоянно говорит мне, что я делаю что-то не так, это мои классы:
возможно, я пропускаючто-то, но я переписывал и рефакторинг, чтобы попытаться найти свою ошибку, но безрезультатно.
Entity:
@Entity
class MovieEntity(
@get:NotBlank
var title: String,
@get:NotBlank
var director: String,
@get:NotBlank
var description: String,
@get:NotBlank
var info: String,
@get:NotNull
var rating: Int,
@get:NotNull
var releaseDate: ZonedDateTime,
@get:Id
@get:GeneratedValue
var id: Long? = null
)
Пользовательский репозиторий
@Repository
interface MovieRepository : CrudRepository<MovieEntity, Long>,
MovieRepositoryCustom
@Transactional
interface MovieRepositoryCustom {
fun createMovie(
title: String,
director: String,
description: String,
info: String,
rating: Int,
releaseDate: ZonedDateTime
) : Long
fun update(
id: Long,
title: String,
director: String,
description: String,
info: String,
rating: Int,
releaseDate: ZonedDateTime
) : Boolean
}
@Repository
@Transactional
class MovieRepositoryImplementation : MovieRepositoryCustom {
@Autowired
private lateinit var entityManager: EntityManager
override fun createMovie(
title: String,
director: String,
description: String,
info: String,
rating: Int,
releaseDate: ZonedDateTime
): Long {
val movie = MovieEntity(title, director, description, info, rating, releaseDate)
entityManager.persist(movie)
return movie.id!!
}
override fun update(
id: Long,
title: String,
director: String,
description: String,
info: String,
rating: Int,
releaseDate: ZonedDateTime
) : Boolean {
val movie = entityManager.find(MovieEntity::class.java, id) ?: return false
movie.title = title
movie.director = director
movie.description = description
movie.info = info
movie.rating = rating
movie.releaseDate = releaseDate
return true
}
}
Затем я пытаюсь запустить тест, чтобы проверить, работает ли он, но затем выдает ошибку приначало:
@RunWith(SpringRunner::class)
@SpringBootTest(classes = [(MovieApplication::class)],
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class RestTest {
@LocalServerPort
var port = 0
@Before
@After
fun clean() {
RestAssured.baseURI = "http://localhost"
RestAssured.port = port
RestAssured.basePath = "/movie"
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails()
val list = RestAssured.given().accept(ContentType.JSON).get()
.then()
.statusCode(200)
.extract()
.`as`(Array<MovieDTO>::class.java)
.toList()
list.stream().forEach {
RestAssured.given().pathParam("id", it.id)
.delete("/{id}")
.then()
.statusCode(204)
}
RestAssured.given().get()
.then()
.statusCode(200)
.body("size()", CoreMatchers.equalTo(0))
}
@Test
fun testCreateMovie() {
val title = "title"
val director = "director"
val description = "description"
val info = "info"
val rating = 4
val releaseDate = ZonedDateTime.now()
val dto = MovieDTO(title, director, description, info, rating, releaseDate)
RestAssured.given().accept(MediaType.APPLICATION_JSON_UTF8_VALUE)
.get()
.then()
.statusCode(200)
.body("size()", CoreMatchers.equalTo(0))
val id = RestAssured.given().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.body(dto)
.post()
.then()
.statusCode(201)
.extract().asString()
RestAssured.given().accept(MediaType.APPLICATION_JSON_UTF8_VALUE)
.get()
.then()
.statusCode(200)
.body("size()", CoreMatchers.equalTo(1))
RestAssured.given().accept(MediaType.APPLICATION_JSON_UTF8_VALUE)
.pathParam("id", id)
.get("/{id}")
.then()
.statusCode(200)
.body("title", CoreMatchers.equalTo(title))
.body("director", CoreMatchers.equalTo(director))
.body("description", CoreMatchers.equalTo(description))
.body("info", CoreMatchers.equalTo(info))
.body("rating", CoreMatchers.equalTo(rating))
.body("releaseDate", CoreMatchers.equalTo(releaseDate))
.body("id", CoreMatchers.equalTo(id))
}