public class MyObjectDAO extends AbstractDAO<MyObject> {
public MyObjectDAO(SessionFactory sessionFactory) {
super(sessionFactory);
}
@UnitOfWork
@Timed
public List<MyObject> getMyObjects(String myObjectId, String status) {
Criteria criteria = criteria();
if (StringUtils.isNotBlank(status)) {
criteria.add(Restrictions.eq("status", status));
}
if (StringUtils.isNotBlank(myObjectId)) {
criteria.add(Restrictions.eq("myObjectId", Long.valueOf(myObjectId)));
}
List myObjects = list(criteria);
LOG.info("\n\n\nNumber of objects found = " + myObjects.size() + "\n\n\n");
return myObjects;
}
Here is my Application class:
public class MyApplication extends Application<MyApplicationConfiguration> {
private final ScanningHibernateBundle<MyApplicationConfiguration> hibernateBundle =
new ScanningHibernateBundle<MyApplicationConfiguration>(ApplicationConstants.MODEL_PACKAGE) {
@Override
public DataSourceFactory getDataSourceFactory(MyApplicationConfiguration configuration) {
return configuration.getDataSourceFactory();
}
};
@Override
public void initialize(Bootstrap<MyApplicationConfiguration> bootstrap) {
bootstrap.addBundle(hibernateBundle);
}
@Override
public void run(MyApplicationConfiguration myApplicationConfiguration,
Environment environment) throws Exception {
final DatabaseHealthCheck databaseHealthCheck = new DatabaseHealthCheck(myApplicationConfiguration.getDataSourceFactory());
SessionFactory sessionFactory = hibernateBundle.getSessionFactory();
final MyObjectDAO templateDAO = new MyObjectDAO(sessionFactory);
final Manager manager = new Manager(templateDAO);
final ManagerResource managerResource = new ManagerResource(manager);
environment.jersey().register(managerResource);
environment.healthChecks().register("database", databaseHealthCheck);
}
public static void main(String[] args) throws Exception {
new MyApplication().run(args);
}
}
The issue I am facing is that I do not see any errors, but no records get returned, when the data for that criteria actually exists. I am not seeing any sql logged in the log files either, even though I have show_sql set to true. I am logging the db url in the database health check class, and that returns the correct value, when I call health check.
I am thinking its an issue with my configuration, and hibernate specifically. The entity classes have been generated.
Also, I tried changing the property name to an incorrect value when specifying restrictions, but no error thrown even then.
Any help would be highly appreciated.
Thanks!