blaze-persistence icon indicating copy to clipboard operation
blaze-persistence copied to clipboard

Support for javax/jakarta.validation in entity views

Open kuhnroyal opened this issue 1 year ago • 4 comments

Hello,

I am looking for a way to enable entity validation for entity view classes when used with Spring Data JPA. Not sure if I missed something but I can't find a way to get blaze repositories to validate the entities.

Is this supported?

kuhnroyal avatar Feb 01 '24 12:02 kuhnroyal

Hi, can you please share more details? Usually, there are two types of validation:

  • Validation on persistence (Hibernate configuration)
  • Validation on request (Spring MVC)

Please show the repositories you are using as well as the invoking code and share the exact expectations.

beikov avatar Feb 01 '24 14:02 beikov

I am talking about validation on persistence. Validation of request bodies is working as expected.

So in this case the email validation works fine as request validation but not when saving a view.

@EntityView(User::class)
@CreatableEntityView
interface InviteUserView {
    @get:IdMapping
    val id: UUID

    @get:Email
    var email: String
}

@Transactional
interface InviteUserViewRepository : EntityViewRepository<InviteUserView, UUID> {
    fun save(user: InviteUserView): InviteUserView
}

@Service
class SomeUserService @Autowired constructor(
	private val repository: InviteUserViewRepository,
) {
	fun saveUser(user: InviteUserView):  InviteUserView {
		return repository.save(user)
    }
}

The repositories are scanned via @EnableBlazeRepositories("....").

kuhnroyal avatar Feb 05 '24 14:02 kuhnroyal

Ok, so validation of creatable/updatable entity views is currently not automatically done when an object is passed to some save method. I'll mark this as feature request then.

beikov avatar Feb 05 '24 17:02 beikov

Ok, thanks!

kuhnroyal avatar Feb 10 '24 21:02 kuhnroyal