Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

querydsl spring data jpa operator precedence

public interface ItemRepository extends JpaRepository<Item, Integer> {
   List<Item> findByNameAndDescriptionIsNullOrDescription(String name, String desc); 
 }

In the native Query, the where condition of findByNameAndDescriptionIsNullOrDescription is translated to

where item0_.NAME=? and (item0_.DESC is null) or item0_.DESC=? 

I need to have where item0_.NAME=? and (item0_.DESC is null or item0_.DESC=?)

I am using the following

  • spring-data-commons-1.6.3.RELEASE.jar

  • spring-data-jpa-1.4.3.RELEASE.jar

  • (i)hibernate-entitymanager-4.2.14.SP1-redhat-1.jar, (ii) hibernate-jpa-2.0-api-1.0.1.Final-redhat-2.jar offered by JBOSS EAP 6.3

like image 321
lab bhattacharjee Avatar asked Feb 16 '16 12:02

lab bhattacharjee


People also ask

What is Querydsl spring?

Querydsl is a framework that enables the construction of statically typed SQL-like queries through its fluent API. Spring Data modules offer integration with Querydsl through QuerydslPredicateExecutor .

What is difference between JpaRepository and CrudRepository?

CrudRepository provides CRUD functions. PagingAndSortingRepository provides methods to do pagination and sort records. JpaRepository provides JPA related methods such as flushing the persistence context and delete records in a batch.

How do I stop Spring Data JPA from doing a select before a save?

The solution is to use @javax. persistence. Version on a new versionNumber column in all the tables. If you have a parent and child table then use @Version column in all the entity classes.

What is Querydsl?

Querydsl is an extensive Java framework, which allows for the generation of type-safe queries in a syntax similar to SQL. It currently has a wide range of support for various backends through the use of separate modules including JPA, JDO, SQL, Java collections, RDF, Lucene, Hibernate Search, and MongoDB.


1 Answers

Probably you can't do that.

Spring Data querydsl is used only for simple SQL queries and if you need something more complex use @Query annotation.

It also would be easier for other developers to understand what query you used instead of analyzing your method name.

like image 178
Orest Avatar answered Oct 12 '22 21:10

Orest