kschlesselmann
09/26/2019, 2:11 PM@Document
class Foo(
test: Set<String>,
val id: UUID = UUID.randomUUID()
) {
private val _test: MutableSet<String> = test.toMutableSet()
val test: Set<String>
get() = _test
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as Foo
return id == other.id
}
override fun hashCode(): Int = id.hashCode()
}
@Repository
interface FooRepository : ReactiveCrudRepository<Foo, UUID>
along with the following test
@DataMongoTest
internal class MutableCollectionTest(
@Autowired private val fooRepository: FooRepository
) {
@Test
fun `should save and retrieve Foo`() {
// Given
val foo = Foo(setOf("a", "b"))
// When
val result = fooRepository.save(foo)
.then(fooRepository.findById(foo.id))
// Then
StepVerifier.create(result)
.expectNext(foo)
.verifyComplete()
}
}
and it fails with: No property test found on entity class ….Foo to bind constructor parameter to!
thanksforallthefish
09/27/2019, 6:41 AM@org.springframework.data.annotation.Transient
val test...
work?
@Transient: By default all private fields are mapped to the document, this annotation excludes the field where it is applied from being stored in the database
source: https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mapping-usage-annotations
make sure you are not using javax.persistence.Transient
though, that is for jpa onlythanksforallthefish
09/27/2019, 6:44 AMtest
in the constructor, as that is the property that is tried to be persisted but fails. but I am just guessing to be honestkschlesselmann
09/27/2019, 6:47 AM@Value("#root._test") test: …
in the constructor and make then
2. private var(!) _test …
as backing property