-->
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: Find with Criteria/Example: object containing a List
PostPosted: Fri Jul 30, 2010 3:37 pm 
Newbie

Joined: Fri Jul 30, 2010 3:33 pm
Posts: 1
hi,

i am trying to execute a find using Criteria/Example on an
Entity that contains a List of enum. consider a class such
as:

@Entity
public class MockEntity extends ModelBase implements Serializable {

@CollectionOfElements()
@Enumerated(EnumType.STRING)
private List<MockEnum> mockEnums;
...
}

here, the enum is defined as:

public enum MockEnum {
GOOD, BAD, OTHER;
}

i am trying to find MockEntity objects containing a prescribed MockEnum
contained in the MockEntity.List<MockEnum> list.

i have created a findByExample() method that utilizes Criteria/Example
to execute the query:

public List<T> findByExample(T exampleInstance, String[] excludeProperty) {
Criteria criteria = getSession().createCriteria(entityClass);
Example example = Example.create(exampleInstance);
if (excludeProperty != null) {
for (int i = 0; i < excludeProperty.length; i++)
example.excludeProperty(excludeProperty[i]);
}
criteria.add(example);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
return criteria.list();
}

i tried calling the findByExample() method as follows:

MockEntity example = new MockEntity();
List<MockEntity.MockEnum> enums = new ArrayList<MockEntity.MockEnum>();
enums.add(MockEntity.MockEnum.OTHER);
example.setMockEnum(enums);
dao = new MockEntityDao();
List<MockEntity> found = dao.findByExample(example, null);

but, the List called found contains all of the MockEntity residing in the
DB -- not merely the MockEntity containing MockEnum.OTHER in
the associated MockEntity.List<MockEnum>.

does anybody have suggestions on how i can achieve this: find
MockEntity objects that contain a prescribed MockEnum in their list?

thank you for your help.


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.