deltaspike-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rafael Pestano <rmpest...@gmail.com>
Subject Re: Criteria select attribute from relashionship
Date Wed, 20 Jul 2016 13:15:58 GMT
Using Jpa criteria it is something like:

 CriteriaBuilder builder = em.getCriteriaBuilder();
        CriteriaQuery<User> query = builder.createQuery(User.class);
        Root<User> root = query.from(User.class);
        Join<User, Tweet> join = root.join(User_.tweets,
javax.persistence.criteria.JoinType.LEFT);
        CriteriaQuery<User> select = query.
                where(builder.like(builder.lower(join.get(Tweet_.content)),
"%tweet%")).
                distinct(true).
                multiselect(root.get(User_.id),root.get(User_.name),
join.get(Tweet_.id), join.get(Tweet_.content), join.get(Tweet_.likes));
                //select(root); all fields
        List<User> users =
em.createQuery(select).setFirstResult(0).setMaxResults(2).getResultList();

is it possible with deltaspike criteria?

2016-07-19 10:56 GMT-03:00 Rafael Pestano <rmpestano@gmail.com>:

> Hi guys,
>
> I have a OneToMany relashionship between entities A and B and want to
> select atributes from B in resulting criteria query, example:
>
> List<User> users = criteria().
>         select(User.class,attribute(User_.id), attribute(User_.name),
> attribute(Tweet_.content)).
>         join(User_.tweets,
>
> where(Tweet.class,javax.persistence.criteria.JoinType.LEFT).
>                 likeIgnoreCase(Tweet_.content, "%tweet%")).
>         distinct().
>         createQuery().setFirstResult(0).setMaxResults(2).
>         getResultList();
>
>
> in example above I was not able to select the column named 'content' from
> Tweet table.
>
> Any ideas? thanks in advance.
>
>
>
> --
> Att,
>
> Rafael M. Pestano
>
> Desenvolvedor Java Cia. de Processamento de Dados do Rio Grande do Sul
> http://rpestano.wordpress.com/
> @realpestano
>



-- 
Att,

Rafael M. Pestano

Desenvolvedor Java Cia. de Processamento de Dados do Rio Grande do Sul
http://rpestano.wordpress.com/
@realpestano

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message