[weld-dev] JPA injection points validations

Robert Marcano robert at marcanoonline.com
Thu Jan 22 11:05:05 EST 2015


On 01/22/2015 11:07 AM, Scott Marlow wrote:
> Do you really want the Hibernate session?  Keep in mind that it is
> managed by the EE container and will be closed when the transaction
> completes or the component invocation ends.

Yes, our codebase don't use JPA APIs, always the Hibernate API, and we 
use the Session with the JTA transaction. We are using many Hibernate 
features not supported by JPA so it doesn't make sense (for us) to mix 
both and make changes when we need to use one of those features.

>
> You can also call
> entityManagerFactory.unwrap(org.hibernate.SessionFactory.class) to get
> the session factory or entityManager.unwrap(org.hibernate.session.class
> to get the session.

I know, I wanted to avoid to make changes to every method that uses the 
session on the existing big codebase. Probably I can change 
@PersistenceContext with an @Inject and use a producer method to inject 
the Session and everyone is happy with a minimal annotation change :)

>
> On 01/22/2015 08:35 AM, 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
>>



More information about the weld-dev mailing list