Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPACrud.createCriteriaByExample does not work as expected #36

Open
cassiobastos opened this issue Sep 1, 2016 · 0 comments
Open

JPACrud.createCriteriaByExample does not work as expected #36

cassiobastos opened this issue Sep 1, 2016 · 0 comments
Assignees
Labels
Milestone

Comments

@cassiobastos
Copy link

No demoiselle 2.3.1, a classe JPACrud implementa o seguinte método:

private CriteriaQuery createCriteriaByExample(final T example) {
final CriteriaBuilder builder = getCriteriaBuilder();
final CriteriaQuery query = builder.createQuery(getBeanClass());
final Root entity = query.from(getBeanClass());

final List predicates = new ArrayList();
final Field[] fields = example.getClass().getDeclaredFields();

for (Field field : fields) {
if (!field.isAnnotationPresent(Column.class) && !field.isAnnotationPresent(Basic.class)
&& !field.isAnnotationPresent(Enumerated.class)) { continue; }

Object value = null;

try
{ field.setAccessible(true); value = field.get(example); }

catch (IllegalArgumentException e)
{ continue; } catch (IllegalAccessException e) { continue; }

if (value == null)
{ continue; }

final Predicate pred = builder.equal(entity.get(field.getName()), value);
predicates.add(pred);
}

return query.where(predicates.toArray(new Predicate[0])).select(entity);
}

No trecho em negrito, poderia ser incluída a anotação JoinColumn.

@juliancesar juliancesar added this to the 2.x milestone Sep 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants