Hi

You are right, neither guice-persist nor guice-jpa provide the option to inject the persistence unit name.
This is because it is kind of a chicken egg problem.

In order to inject the persistence unit name you need an injector, then on the other hand you can't have the injector before configuring the modules... I guess you could build a persistence extension which instead of taking the name in the constructor just requires a binding with a given name to be defined (I may consider this for a next release of gucie-jpa).

But for now it is not easily doable. What I usually do is collect all the information needed to configure the injector in a single property file. And then do it the "old Java" way, load that one file using java.util.Properties and java.lang.ClassLoader.getResourceAsStream(String). I like this because the settings for configuring guice are separated from the rest and are all in a single place. In most projects I have not more than 3 settings in this properties file.

Hope this helps


On 06/24/2013 10:14 PM, Daniel Bimschas wrote:
Hi,

I've just discovered this thread and I find myself in a somewhat similar situation as described by Martin, working with guice-persist. In my case I have a POJO holding the applications configuration which gets injected itself from bound constants loaded from a properties file. So (from my understanding) at the time of installing the guice-persist module, the POJO instance can't be created/injected yet as we're still in the phase of configuring the bindings, so I can't access the POJOs fields to load the properties for the guice-persist module.

I've also discovered https://github.com/sclassen/guice-jpa which looks like its able to solve one of my other issues but I couldn't figure out how to solve this runtime configuration issue with it either.

Any ideas?

Cheers,
Daniel


On Wednesday, 26 September 2012 10:11:08 UTC+2, Martin Schayna wrote:

    Hi,

    I have small API server application based on Jersey, Hibernate/JPA
    and Guice, running in Tomcat. I want to use guice-persist
    extension for better handling EntityManager instances and
    transactions. Now I'm doing the whole work in each controller
    method, so each method creates EntityManager, starts transaction,
    close everything etc. The guice-persist thing looks pretty
    straightforward, but I don't know how to handle this:

    I have only one persistence-unit, but application caches more
    EntityManagerFactory instances, each with its own properties.
    These properties are loaded from configuration on runtime. I
    cannot configure GuiceServletContextListener with module
    JpaPersistModule("unit").properties(myProperties) because
    myProperties are based on request parameters -- my application
    supports multi-tenancy and tenants has data in several similar
    databases.

    How can I use guice-persist with this scenario?

    Thanks,
    Martin Schayna

--
You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.



--
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to