Spring Data JPA contains ignorecase Example

In this tutorial, we will see Spring Data JPA contains ignorecase Example using Spring Boot and oracle.

Let’s see how to define the Query method(Query creation from method names) using Spring Data JPA Containing and IgnoreCase Keywords.

Consider we have an entity called Student.java as below.

 

and we have some record in the database as below.

Spring Data JPA contains ignorecase

 

Query method using Containing and IgnoreCase.

public List<Student> findByNameContainingIgnoreCase(String name);

 

Generated Query.

Hibernate:
select
student0_.id as id1_0_,
student0_.name as name2_0_,
student0_.roll_number as roll_number3_0_,
student0_.university as university4_0_
from
student student0_
where
upper(student0_.name) like upper(?)

 

Spring Data JPA contains ignorecase Example

 

 

Repository Example.

 

Spring Data JPA Containing and IgnoreCase example using   Spring Boot and oracle.

Open eclipse and create maven project, Don’t forget to check ‘Create a simple project (skip)’ click on next.  Fill all details(GroupId – springdatacontainingignorecase, ArtifactId – springdatacontainingignorecase and name – springdatacontainingignorecase) and click on finish. Keep packaging as the jar.

Modify pom.xml

Note – In pom.xml we have defined javac.exe path in configuration tag. You need to change accordingly i.e where you have installed JDK.

If you see any error for oracle dependency then follow these steps.

Directory structure –

Spring Data JPA Like and Containing

 

 

Student.java

StudentController.java

 

Note – See more details about @Controller and RestController here.

StudentRepository.java – interface

StudentService.java – interface

Note – See here more about @Component, @Controller, @Service and @Repository annotations here.

StudentServiceImpl.java

SpringMain.java

Note – See more details about @ComponentScan here.

JpaConfig.java

Note – See more details about @Configuration annotations here.

application.properties

Let’s run the SpringMain class(run as java application).

Perform saveall operation first using below REST API.

http://localhost:9091/student/saveall

 

Response Data.

 

http://localhost:9091/student/containingignoreCase/john

Spring Data JPA like ignorecase

 

Note – Try below API(Change the name)

http://localhost:9091/student/containingignoreCase/johN

http://localhost:9091/student/containingignoreCase/JOHN

http://localhost:9091/student/containingignoreCase/JOhn

 

You should get three records always because we are using Containing and IgnoreCase together in our Query Method.

 

That’s all about Spring Data JPA contains ignorecase Example using Spring Boot and oracle.

 

You may like.

 

Other Spring Data JPA and Hibernate tutorials.

 

Spring Data JPA Docs.

 

 

Top