Closed Ryszard-Trojnacki closed 5 years ago
Hmmm. I'm not that keen on this approach to generate query beans and much prefer using annotation processors. I've got a lot on my plate so can you look into this yourself, debug it and prepare a PR?
OK, I will check this.
OK. I have found the cause of this problem.
This is because of fields:
/** Informacja o liczbie miejsc w pokojach */
@DbArray(length = 32)
@Column(name = "rooms", nullable = false)
private List<Integer> rooms=new ArrayList<>();
@DbArray(length = 9*400)
@Column(name = "prices", nullable = false)
private List<Long> prices=new ArrayList<>();
For those fields SimpleQueryBeanWriter.addClassProperties
-> GenerationMetaData.getPropertyType
is returning PropertyTypeArray
:
if (EntityBeanPropertyReader.dbArrayField(field)) {
String collectParamType = deriveCollectionParameterType(field.signature);
String shortType = langShortType(deriveShortName(collectParamType));
return new PropertyTypeArray(collectParamType, shortType);
}
And PropertyTypeArray.addImports
:
@Override
public void addImports(Set<String> allImports) {
super.addImports(allImports);
allImports.add(elementClass);
}
Just adds this type to imports - elementClass
which is java.lang.Integer
.
Then it is replaced by/in SimpleQueryBeanWriter.translateKotlinImportTypes
, which is called no matter what.
Not sure hot to fix this:
translateKotlinImportTypes
.java.lang.Integer
in PropertyTypeArray.addImports.First thing I can make without any problems - it is just one if
.
Second thing I'm not sure how to make.
Should I only do the first thing?
And i think same thing is with QAssoc...
.
Good work!!
One option is to check in SimpleQueryBeanWriter if is Kotlin and only then call translateKotlinImportTypes.
Yes. Lets definitely do option 1.
Second is to ignore import for java.lang.Integer in PropertyTypeArray.addImports.
I suspect we want to ignore that import for Java or conversely it might be a better approach when using Java to remove all imports for java.lang.* (that might be simpler/cleaner).
Yeah. I'll need to have a look on this second point.
I'm using
io.ebean.tools:finder-generator:11.34.1
to generate QueryBeans, and evething works OK, but for one class generator started at some point to generate Kotlin imports. Generated class:Same for Assoc class for this entity:
Generated code is Java, but imports for Int and Long is from Kotlin. In my project I have other 12 entity classes, but only for this one I have Kotlin imports: