Open hamidsultanzadeh opened 12 months ago
The error is occurring because both BaseEntity and IsDeletedEntity have a method named builder() that causes a name clash due to erasure when you use a generic type for BaseEntity.
Create a separate builder for BaseEntity and specify the type parameter there:
@Data
@SuperBuilder(builderMethodName = "baseEntityBuilder")
Use baseEntityBuilder() instead of builder() when constructing instances of BaseEntity:
BaseEntity
It works!
Thank you
That's a limitation due to static method "overriding" in Java (which is not a real overriding).
If feasable, you could make IsDeletedEntity
abstract. That would suppress the generation of the builder
method.
thanks @janrieke I appreciate your help Yeah, it is about static methods. but I am not sure why I getting clash after putting generic type on BaseEntity.
I have been trying to make an architecture for my database models. and I'm using BaseEntity and IsDeletedEntity for storing common fields. and BaseEntity accepts a generic but IsDeletedEntity doesn't. So let me give you an example from my models:
It is my child model which extends BaseEntity model with generic Long type
The BaseEntity
IsDeletedEntity
And finally, the error is
java: name clash: <ID>builder() in com.webperside.courseerpbackend.models.mybatis.base.BaseEntity and builder() in com.webperside.courseerpbackend.models.mybatis.base.IsDeletedEntity have the same erasure, yet neither hides the other
Actually, there is a solution to fix it. If you just add a generic to IsDeletedEntity, and pass it from BaseEntity, it will work. But I want to follow that way, otherwise, I have to create a dummy generic for IsDeletedEntity. which I don't need it in this model.
Version info (please complete the following information):
Platform IntelliJ IDEA 2023.1 (Community Edition) Build #IC-231.8109.175, built on March 28, 2023 Runtime version: 17.0.6+10-b829.5 aarch64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 13.5.1 GC: G1 Young Generation, G1 Old Generation Memory: 2048M Cores: 8 Metal Rendering is ON Registry: debugger.new.tool.window.layout=true ide.experimental.ui=true
Non-Bundled Plugins: Docker (231.8109.217) com.liuzhihang.toolkit.mybatis-jump (1.0.1) GsonFormatPlus (1.6.1) com.intellij.lang.jsgraphql (4.0.0) com.bruce.intellijplugin.generatesetter (2.8.3) wl-spring-assistant (1.2.222.231)
Kotlin: 231-1.8.20-IJ8109.175