micronaut-data icon indicating copy to clipboard operation
micronaut-data copied to clipboard

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

Open jboka opened this issue 3 years ago • 4 comments

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

  • JDK: 17

Example Application

No response

Version

3.2.*

jboka avatar Dec 20 '21 16:12 jboka

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 avatar Dec 21 '21 11:12 dstepanov

@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.

dstepanov avatar Jan 14 '22 09:01 dstepanov

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?

alimac avatar Sep 08 '22 17:09 alimac