Hi everybody,

I am writing a library that needs to do some database initialization
at startup time. The library will be used in standalone applications
and in web applications. After having read the docs, I came to the
conclusion that I should use WorkManager to execute the SQL statements
at boot time. My understanding of WorkManager is that whatever the
UnitOfWork is in the app, I can use the WorkManager for situations
where I manually specify (beginWork/endWork) the boundaries of my unit
of work.

Something seems to be wrong, however. I have a test application
(actually, a unit test) that installs a module like this:

  protected void configure()
  {
    install(PersistenceService.usingHibernate().across
(UnitOfWork.TRANSACTION).buildModule());

    // Database configuration
    Properties properties = new Properties();
    properties.setProperty("hibernate.connection.driver_class",
"org.h2.Driver");
    properties.setProperty("hibernate.dialect",
"org.hibernate.dialect.H2Dialect");
    properties.setProperty("hibernate.connection.url",
"jdbc:h2:mem:"); // in-memory db
    properties.setProperty("hibernate.current_session_context_class",
"thread");
    properties.setProperty("hibernate.connection.provider_class",
"org.hibernate.connection.C3P0ConnectionProvider");
    /*...*/
    bind(Configuration.class).toInstance(new AnnotationConfiguration
()./*...*/setProperties(properties));

    // Populate the database
    bind(QuartzDatabasePopulator.class).toInstance(new
QuartzDatabasePopulator());
  }

The last line is a binding to a class that populates the DB with the
OpenSymphony Quartz tables, if needed. It uses WorkManager's beginWork
() and endWork() and a Provider<Session> to do the actual work. But I
get:

Caused by: java.lang.IllegalStateException: Cannot use WorkManager
with UnitOfWork.TRANSACTION

It seems that my understanding of WorkManager is wrong. Could somebody
clarify this?

Also, if WorkManager is the wrong mean, how can I get a Hibernate
session via Guice?

Thanks,
Kaspar
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to