I'm doing the integration tests with Apache OpenEJB (tomee). The bind is 
done when the container is started.



Em quarta-feira, 28 de setembro de 2016 14:12:46 UTC-3, scl escreveu:
>
> Where do you bind the EntityManager? Is it bound just in time? At runtime 
> do you have a container or similar which provides the EntityManager?
>
> Am 28. September 2016 17:20:16 MESZ, schrieb "Robério Cardoso Fernandes" <
> [email protected] <javascript:>>:
>>
>> Hi folks,
>> I'm doing the unit tests in my project, and I'm trying to use the Google 
>> Guice. My repository classes have your EntityManagers, and, in my project, 
>> to specify the persistence unit I have an annotation:
>>
>> @javax.inject.Qualifier
>> @java.lang.annotation.Retention(RUNTIME)
>> @java.lang.annotation.Target({FIELD, TYPE, METHOD})
>> public @interface ConnectionDatabase {
>> }
>>
>>
>> In my repositories the entity managers are injected like this:
>>
>> public class MyRepository implements IMyRepository {
>>
>>     @javax.inject.Inject
>>     @ConnectionDatabase
>>     private javax.persistence.EntityManager entityManager;
>> }
>>
>>
>> M ResourceProducer, like this:
>>
>> public class ResourceProducer {
>>
>>     @javax.enterprise.inject.Produces
>>     @Inject
>>     @ConnectionDatabase
>>     private javax.persistence.EntityManager entityManager;
>> }
>>
>>
>> My Module of Google Guice is like this:
>>
>> public class ModuleTest extends AbstractModule {
>>
>>     @Override
>>     public void configure() {
>>         bind(new TypeLiteral<IMyRepository>() {}).to(MyRepository.class);
>>     }
>> }
>>
>>
>> I have a persistence.xml with a persistence unit called "TestPU".
>>
>>
>> In my unit tests (or cintegration tests), using the Google Guice, the 
>> EntityManager is not injected, and the following error is occurring:
>> No implementation for javax.persistence.EntityManager annotated with 
>> @ConnectionDatabase() was bound.
>>   while locating javax.persistence.EntityManager annotated with 
>> @ConnectionDatabase()
>>     for field at MyRepository.entityManager(<the line>)
>>   at ModuloTest.configure(<the line of the bind "bind(new 
>> TypeLiteral<IMyRepository>() {}).to(MyRepository.class)">)
>>
>>
>> Someone here can help me, please?
>>
>>

-- 
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 https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/fc26fa51-d3c1-4f17-a4f5-cd7f72c6eade%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to