[weld-dev] JPA injection points validations

Scott Marlow smarlow at redhat.com
Thu Jan 22 10:37:39 EST 2015


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.

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.

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