-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem Criteria with composite POJO in SELECT
PostPosted: Tue Jun 17, 2014 11:59 am 
Newbie

Joined: Thu Dec 28, 2006 12:24 pm
Posts: 5
Location: Brazil
I want to create a criteria with a custom POJO
properties:
UserPojo
Code:
   private Long id;
   private String name;
   private Long localeId;
   private List<GroupPojo> groups;

GroupPojo
Code:
   private Long id;
   private String name;


my criteria code is:

Code:
   final CriteriaBuilder criteria = this.getEntityManager().getCriteriaBuilder();
   CriteriaQuery<IGesplanEntity<?>> criteriaQuery = (CriteriaQuery<UserPojo>) criteria.createQuery(UserPojo.class);
   final Root<T> root = criteriaQuery.from(User.class);
   List<Selection<?>> selections = new ArrayList<>();
   Field[] iFields = UserPojo.class.getDeclaredFields();
   for (Field field : iFields) {
      Path<Object> fieldPath = root.get(field.getName());
      if (Collection.class.isAssignableFrom(field.getType())) {
         Join<Object, Object> join = root.join(field.getName());
         Field[] iFields1 = clazz.getDeclaredFields();
         for (Field field2 : iFields1) {
            selections.add(join.get(field2.getName()));
      }
      } else {
         selections.add(fieldPath);
      }
   }
   Selection<? extends IGesplanEntity<?>> select = (Selection<? extends IGesplanEntity<?>>) ((CriteriaBuilderImpl) criteria).construct(entity.getClass(), selections);
   criteriaQuery.select(select);
   final TypedQuery<IGesplanEntity<?>> query = this.getEntityManager().createQuery(criteriaQuery);
   query.getResultList()


but i got a problem, when it will do the select for my GroupPojo it dont add new GroupPojo in query.

i want the the ouput is

Code:
select new UserPojo(u.id, u.name, u.localeId, new list(new GroupPojo(g.id, g.name)) from User as u inner join u.group as g

but i dont know how to made it with criteria, can anyone help?

i got almost
Code:
select new UserPojo(u.id, u.name, u.localeId) from User as u inner join u.group as g
(using where condition)
i could get too
Code:
select new UserPojo(u.id, u.name, u.localeId, g.id, g.name) from User as u inner join u.group as g
(but it is not a list)
but i need the list of my GroupPojo. I search in google and forum but not found a solution.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.