Closed dmanix closed 1 year ago
Have you tried steps described here? By creating a custom NamingStrategy in steps described above and creating a custom annotation processor with the naming strategy you should be able to modify this behavior.
@lpandzic yes I was trying this, but I can't do what I need. As I understand NamingStrategy interface allows to customize generated Q-classes (e.g. change default alias table name, etc.). But I need to change table real name (from database). If I understand correctly annotaion processor code, defining table name is done in function getTableName from CustomExtendedTypeFactory class:
protected String getTableName(EntityType model) {
var simpleName = model.getSimpleName();
var className = model.getPackageName() + "." + simpleName;
var tableName = CaseFormat.UPPER_CAMEL.to(tableCaseFormat, simpleName);
return Optional.ofNullable(elements.getTypeElement(className)
.getAnnotation(Table.class))
.map(this::getTableName)
.orElse(tableName);
}
NamingStrategy class is not used here, so I'd like to redefine this getTableName method in my subclass, but I encounter problems described in my earlier comment.
You are right, I've reverted to original proposal to make CustomExtendedTypeFactory public. Try it out with 8.1.0
In my Spring Data JDBC project I have custom NamingStrategy (predefined prefix is added to entity name):
I want to have the same table names generated by AnnotationProcessor in Q-classes. What is recommended way to adjust it in AnnotationProcessor?
It seems that enough should be: 1) writing my own ExtendedTypeFactory implementation which extends CustomExtendedTypeFactory and overrides one method: getTableNameEntityType model). 2) overriding createTypeFactory method of SpringDataJdbcAnnotationProcessorBase and use implementation of ExtendedTypeFactory (created in first step) instead of CustomExtendedTypeFactory
But it turns out it is impossible due to CustomExtendedTypeFactory class visibility issue. What is the reason this class is not an public class?