[weld-dev] JPA injection points validations

Scott Marlow smarlow at redhat.com
Thu Jan 22 11:13:04 EST 2015


On 01/22/2015 10:59 AM, Robert Marcano wrote:
> I haven't found a way to override Weld detection of the @Persistence*
> annotations, or add a new one, I may be wrong but probably Wildfly just
> doesn't delegate to Weld for @Persistence*

Yes, I think your right.  Related WildFly code is at:
https://github.com/wildfly/wildfly/blob/master/jpa/src/main/java/org/jboss/as/jpa/processor/JPAAnnotationProcessor.java
+
https://github.com/wildfly/wildfly/blob/master/jpa/src/main/java/org/jboss/as/jpa/injectors/PersistenceContextInjectionSource.java

>
> On 01/22/2015 10:52 AM, Jozef Hartinger wrote:
>> Validation *is* done by *InjectionServices. However, the
>> JpaInjectionServices SPI is built with the following assumption of types:
>>
>> @PersistenceContext -> EntityManager
>> @PersistenceUnit -> EntityManagerFactory
>>
>> which seems as a reasonable assumption given that e.g.
>> @PersistenceContext Javadoc says that:
>>
>> "Expresses a dependency on a container-managed *EntityManager*"
>>
>> All the other validation is left for the service implementation. For the
>> other *InjectionServices, no validation (even the type) is performed by
>> Weld.
>>
>> HTH,
>>
>> Jozef
>>
>> On 01/22/2015 02:35 PM, Robert Marcano wrote:
>>> I have noticed that all *InjectionServices javadoc say that those
>>> implementations should do the required injection point validations. for
>>> example JpaInjectionServices
>>>
>>> "Register a persistence context injection point. The implementation
>>> validates the injection point ..."
>>>
>>> But for some reason if a JpaInjectionServices implementation is
>>> registered, an internal validation is triggered
>>>
>>> "WELD-001517: The type of the resource producer field
>>> [[BackedAnnotatedField] @PersistenceContext private
>>> com.example.TestBean.session] does not match the resource type interface
>>> javax.persistence.EntityManager" See [1]
>>>
>>> This field class is an Hibernate session, Wildfly support injecting that
>>> using @PersistentContext [2], but this validations is blocking me to do
>>> the same in a mock test environment I am coding. I am not sure how
>>> Wildfly inject it with Weld or if they skip Weld injecting JPA instances
>>> because of this. Why this validation is harcoded on Weld, when for
>>> example EjbInjectionServices doesn't force any predefined validation?
>>>
>>> Shouldn't it be removed and leave that validation to the
>>> JpaInjectionServices implementation as the javadoc say it is its
>>> responsibility?.
>>>
>>>
>>> [1]
>>> https://github.com/weld/core/blob/master/impl/src/main/java/org/jboss/weld/injection/ResourceInjectionFactory.java#L306
>>>
>>> [2]
>>> https://docs.jboss.org/author/display/WFLY8/JPA+Reference+Guide#JPAReferenceGuide-InjectionofHibernateSessionandSessionFactoryInjectionofHibernateSessionandSessionFactory
>>>
>>> _______________________________________________
>>> weld-dev mailing list
>>> weld-dev at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/weld-dev
>>
>
> _______________________________________________
> weld-dev mailing list
> weld-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/weld-dev
>


More information about the weld-dev mailing list