micronaut-projects / micronaut-data

Ahead of Time Data Repositories
Apache License 2.0
466 stars 197 forks source link

Repository update is not working with @Where on repository and @JoinTable in entity #1250

Open jboka opened 2 years ago

jboka commented 2 years ago

Expected Behavior

Calling the update method of a repository with @Where and of an entity containing a @JoinTable mapping should update this entity accordingly. In version 3.1.2 it worked fine.

Actual Behaviour

The application thows following exception:

java.lang.IllegalArgumentException: org.hibernate.QueryException: Components currently not assignable in update statements

Steps To Reproduce

Unfortunately, I could not reproduce the scenario in isolation, because of other issues regarding the test project-setup.

Basically I have an DTO which looks like this:

@Entity
@Table(name="posts")
data class PostDTO {
  @Id
  val id: UUID,
  val title: String,
  val deleted: Boolean,
  @OneToOne(cascade = [CascadeType.ALL])
  @JoinTable(
    name = "post_xyz",
     joinColumns = [JoinColumn(name = "post_id")],
     inverseJoinColumns = [
        JoinColumn(name = "xyz_id", referencedColumnName = "id"),
        JoinColumn(name = "tenant", referencedColumnName = "tenant"),
    ],
  )
  val xyz: XyzDTO?,
}

The repository looks like this:

@Repository
@JoinSpecifications(
    Join(value = "xyz", type = Join.Type.LEFT_FETCH)
)
@Where("postDTO_.deleted = false")
interface PostRepository : ReactiveStreamsCrudRepository<PostDTO, UUID> {
  fun update(post: PostDTO): Mono<PostDTO>
  //...
}

If needed I will try to provide a working sample project, but maybe someone can already see the issue. Let me know.

Environment Information

Example Application

No response

Version

3.2.*

dstepanov commented 2 years ago

It would be the best to provide a sample project, I don't see anything strange, maybe if you post full exception and generated query.

dstepanov commented 2 years ago

@jbtippelt I can replicate it now, it looks like after we fixed generating an update with a query that includes the where statement it started to generate incompatible JPQL. We would need to add something like @NoWhere or @JpaUpdate/@JpaMerge to only call the underlying method.

alimac commented 2 years ago

Just ran into this bug in 3.4 -- skimmed the release notes but it seems like there is no fix for it yet. Is the only workaround removing @Where annotation?