You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@deltaspike.apache.org by Luís Alves <lu...@gmail.com> on 2017/12/19 14:27:54 UTC
QueryInvocationContext is null.
I have the following code:
@Repository
public abstract class ConfigurationRepository extends
AbstractEntityRepository<Configuration, Long> implements
EntityRepository<Configuration, Long>, EntityManagerDelegate<
Configuration>
{
* // FIXME: why this is null?!? @Inject private
QueryInvocationContext context;*
@Inject
private EntityManager em;
/**
* Find by key.
*
* @param key
* the key
* @return the configuration
*/
public Configuration findByKey(String key)
{
QConfiguration c = QConfiguration.configuration;
return new JPAQuery<Configuration>(em).from(c).where(c.key.eq(key)).
fetchFirst();
}
}
The *QueryInvocationContext*is null so I had to inject the EM directly. Any
idea why it's null or how to figure out why it's null?
Regards,
LA
Re: QueryInvocationContext is null.
Posted by "John D. Ament" <jo...@apache.org>.
The abstract classes probably only support limited injection. I wouldn't
recommend doing this, if you need access to EntityManager there are helper
classes to implement that give you it, e.g. EntityManagerAware.
John
On Tue, Dec 19, 2017 at 10:16 AM Luís Alves <lu...@gmail.com> wrote:
> I have the following code:
>
> @Repository
> public abstract class ConfigurationRepository extends
> AbstractEntityRepository<Configuration, Long> implements
> EntityRepository<Configuration, Long>, EntityManagerDelegate<
> Configuration>
> {
>
>
> * // FIXME: why this is null?!? @Inject private
> QueryInvocationContext context;*
>
> @Inject
> private EntityManager em;
>
> /**
> * Find by key.
> *
> * @param key
> * the key
> * @return the configuration
> */
> public Configuration findByKey(String key)
> {
> QConfiguration c = QConfiguration.configuration;
>
> return new
> JPAQuery<Configuration>(em).from(c).where(c.key.eq(key)).
> fetchFirst();
> }
>
> }
>
> The *QueryInvocationContext*is null so I had to inject the EM directly. Any
> idea why it's null or how to figure out why it's null?
>
> Regards,
> LA
>