error: Public method inherits AOP advice but is declared final. Micronaut 4

243 Views Asked by At

During my upgrade to micronaut 4, the data classes with the annotation

io.micronaut.configuration.hibernate.jpa.proxy.GenerateProxy

Cause build error:

error: Public method inherits AOP advice but is declared final. Either make the method non-public or apply AOP advice only to public methods declared on the class.
public final java.util.UUID component1() {

Here is an example of a class that causes the issue:

import com.fasterxml.jackson.annotation.JsonInclude
import io.micronaut.configuration.hibernate.jpa.proxy.GenerateProxy
import java.util.UUID
import jakarta.persistence.Cacheable
import jakarta.persistence.Entity
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.OneToOne
import jakarta.persistence.Table
import org.hibernate.annotations.BatchSize
import org.hibernate.proxy.HibernateProxy

@Entity
@Table(name = EntityConstants.TableNames.RFP_PROJECT, schema = EntityConstants.SCHEMA)
@BatchSize(size = EntityConstants.BATCH_SIZE)
@Cacheable
@GenerateProxy
@JsonInclude(JsonInclude.Include.NON_EMPTY)//hopefully this works at some later version
data class RfpProject(
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    val id: UUID?,
    val name: String,
    @OneToOne
    val rfpEvent: RfpEvent?
) {
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other == null) return false
        val oEffectiveClass =
            if (other is HibernateProxy) other.hibernateLazyInitializer.persistentClass else other.javaClass
        val thisEffectiveClass =
            if (this is HibernateProxy) this.hibernateLazyInitializer.persistentClass else this.javaClass
        if (thisEffectiveClass != oEffectiveClass) return false
        other as RfpProject

        return id != null && id == other.id
    }
    override fun hashCode(): Int = javaClass.hashCode()

    override fun toString(): String {
        return this::class.simpleName + "(id = $id , name = $name , rfpEvent = $rfpEvent )"
    }
}

the allOpen plugin is configured to include all classes annotated with jakarta.persistence.Entity

If I remove the GenerateProxy annotation or I make the class NOT a data class I have no issues but I'd want to keep both.

0

There are 0 best solutions below