Dropwizard Hibernate configuration help

1,003 views
Skip to first unread message

AP

unread,
Apr 29, 2015, 1:06:37 PM4/29/15
to dropwiz...@googlegroups.com
I am trying to migrate an existing application to dropwizard (version 0.8.1).  This is what my yaml file looks like:
server:
type: simple
applicationContextPath: /myApp
adminContextPath: /admin
connector:
type: http
port: 8080
bindHost: 127.0.0.1

database:
driverClass: oracle.jdbc.OracleDriver
user: me
password: my_password
url: jdbc:oracle:thin:@something.something.com:18764/orcltest
logValidationErrors: true
validationQuery: select 1 from dual
properties:
hibernate.dialect: org.hibernate.dialect.Oracle10gDialect
hibernate.bytecode.use_reflection_optimizer: false
hibernate.cache.provider_class: org.hibernate.cache.NoCacheProvider
# hibernate.current_session_context_class: thread
hibernate.show_sql: false

logging:
level: DEBUG
# Logger-specific levels.
loggers:
org.hibernate.SQL: ALL
org.hibernate.type: ALL

appenders:
- type: file
currentLogFilename: ./logs/myApp.log
# threshold: ALL
archive: true
archivedLogFilenamePattern: ./logs/myApp-%d.log.gz
archivedFileCount: 5
timeZone: UTC
logFormat: # TODO

This is extract of the DAO class I am using:

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!

Carlo Barbara

unread,
Apr 30, 2015, 9:24:55 AM4/30/15
to dropwiz...@googlegroups.com

A couple of things you can try:

1) you can try setting the logger org.hibernate to ALL, that should increase logging
2) Run this an IDE with a debugger, step into list(criteria)
3) Turn on query logging in your db while you debug

--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-us...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aparna Parikh

unread,
Apr 30, 2015, 10:17:36 AM4/30/15
to dropwiz...@googlegroups.com
I replaced ScanningHibernateBundle with HibernateBundle and everything seems to work better! 
I had specified the package name such com.somePkg.otherPkg where otherPkg is the package that contains the entity classes. I will revisit the correct syntax for specifying the package name to the ScanningHibernateBundle, but for not spelling out each of the Entity classes with the HibernateBundle works.

--
You received this message because you are subscribed to a topic in the Google Groups "dropwizard-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dropwizard-user/t-Hme-8jKP8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dropwizard-us...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages