brettwooldridge / SansOrm

A "No-ORM" sane SQL ←→ Java object mapping library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Table annotation shouldn't be mandatory

NicolaIsotta opened this issue · comments

Right now, for CRUD operations, database table name is evaluated in this method:

/**
* Get the table name specified by the {@link Table} annotation.
*/
private void extractClassTableName() {
final Table tableAnnotation = clazz.getAnnotation(Table.class);
if (tableAnnotation != null) {
final String tableName = tableAnnotation.name();
this.tableName = tableName.isEmpty()
? clazz.getSimpleName() // as per documentation, empty name in Table "defaults to the entity name"
: tableName;
}
}

If the class does not have the @Table annotation, tableName is null and this could lead to various type of confusing exception from the jdbc drivers, such as: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near the keyword 'null'.

Is the a reason why this method does not default to clazz.getSimpleName() when there is no @Table annotation?