Quantcast
Channel: GUJ - Tópicos com a tag hibernate
Viewing all articles
Browse latest Browse all 759

Criteria API Hibernate

$
0
0

@Ms1403 escreveu:

Galera estou tentando criar uma pesquisa dinamica usando criteria, mas quando executo tal metódo a clausula where vem com ANDs e não com OR. Gostaria de fazer algo do tipo: where field like parameter OR anotherField like parameter e assim por diante, mas a query só vem com AND. Alguém por favor me da uma luz

public List<T> findByParameter(List<String> elements){	
		Class<?> generic = this.clazz;
		CriteriaBuilder criteriaBuilder = this.manager.getCriteriaBuilder();
		CriteriaQuery<T> query = criteriaBuilder.createQuery(this.clazz);
		Root<T> root = query.from(this.clazz);
		List<Predicate> predicates = new ArrayList<Predicate>();		
		for(String element : elements){
			while (generic != null) {
				for (Field field : generic.getDeclaredFields()) {
					field.setAccessible(true);
					if(field.getType() == String.class){
						predicates.add(criteriaBuilder.like(root.get(field.getName()), "%" + element + "%"));
					}
				}
				generic = generic.getSuperclass();

			}
		}
		query.where((Predicate[])predicates.toArray(new Predicate[0]));
		List<T> resultList = this.manager.createQuery(query).getResultList();
		resultList.stream().forEach(System.out::println);
		return resultList;
	}

Mensagens: 1

Participantes: 1

Ler tópico completo


Viewing all articles
Browse latest Browse all 759

Trending Articles


Girasoles para colorear


Pokemon para colorear


Gwapo Quotes : Babaero Quotes


Love Quotes Tagalog


Two timer Sad tagalog Love quotes


Inggit Quotes and Kabit Quotes – Tagalog Patama Quotes


5 Uri ng Pambobola


Best Love Life Quotes Collection


Vimeo 10.7.0 by Vimeo.com, Inc.


Vimeo 10.7.1 by Vimeo.com, Inc.


RE: Mutton Pies (frankie241)


Sapos para colorear


tagalog love Quotes – Tiwala Quotes


Long Distance Relationship Tagalog Love Quotes


Ligaw Quotes – Courting Quotes – Sweet Tagalog Quotes


INUMAN QUOTES


Hugot Lines 2020 Patama : ML Edition


Re:Mutton Pies (lleechef)


EASY COME, EASY GO


FORECLOSURE OF REAL ESTATE MORTGAGE



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>