Add exception handling for entity scanning in `DatabaseManager`
- Wrap entity scanning in a try-catch block to handle potential exceptions. - Log descriptive error messages and throw a runtime exception for failure cases. - Warn if no `@Entity` classes are found during the scan.
This commit is contained in:
parent
e395e21e8c
commit
081a1f1ed4
|
|
@ -117,10 +117,20 @@ public abstract class DatabaseManager {
|
||||||
configuration.getProperty("hibernate.format_sql", "true"));
|
configuration.getProperty("hibernate.format_sql", "true"));
|
||||||
|
|
||||||
logger.info("Scanning for entities in package: com.mediamanager.model");
|
logger.info("Scanning for entities in package: com.mediamanager.model");
|
||||||
|
|
||||||
|
Set<Class<?>> entityClasses;
|
||||||
|
try {
|
||||||
Reflections reflections = new Reflections("com.mediamanager.model", Scanners.TypesAnnotated);
|
Reflections reflections = new Reflections("com.mediamanager.model", Scanners.TypesAnnotated);
|
||||||
Set<Class<?>> entityClasses = reflections.getTypesAnnotatedWith(Entity.class);
|
entityClasses = reflections.getTypesAnnotatedWith(Entity.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Failed to scan for entities: {}", e.getMessage());
|
||||||
|
throw new RuntimeException("Entity scanning failed", e);
|
||||||
|
}
|
||||||
|
|
||||||
logger.info("Found {} entities", entityClasses.size());
|
logger.info("Found {} entities", entityClasses.size());
|
||||||
|
if (entityClasses.isEmpty()) {
|
||||||
|
logger.warn("No @Entity classes found in package com.mediamanager.model - is this expected?");
|
||||||
|
}
|
||||||
for (Class<?> entityClass : entityClasses) {
|
for (Class<?> entityClass : entityClasses) {
|
||||||
logger.debug("Registering entity: {}", entityClass.getSimpleName());
|
logger.debug("Registering entity: {}", entityClass.getSimpleName());
|
||||||
hibernateConfig.addAnnotatedClass(entityClass);
|
hibernateConfig.addAnnotatedClass(entityClass);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue