Monday, 15 March 2010

java - Querying Data with a predicate and paging using Spring Data JPA -



java - Querying Data with a predicate and paging using Spring Data JPA -

i have had misfortune of working in java time, coming .net world. ranting aside, looking implement repository can handle utilize of predicates , must have pagination. unable find way this.

// icontactrepository.java public interface icontactrepository extends repository<contact,long> { } // application.java contactrepo.findall(predicate, new pagerequest(0,10));

i want to able find contacts contact name containing search term or contact phone number containing search term , first 10 matches.

in .net world, if not using orm utilize sql server's awesome tsql want stuck oracle here. otherwise utilize orm , pass lambda query function predicate.

in configuration using jpa , spring. (for static predicates. if want add together predicates(search terms) dynamically please allow me know.)

// icontactrepository.java public interface icontactrepository extends crudrepository<contact,long>, pagingandsortingrepository<contact, long> { list<contact> findbycontactnamelikeandcontactphonelike(string name, string phone, pageable pageable) }

i tried pageable crudrepo , works fine. , lambda right :)

in configuration implementation looks :

icontactrepository contactrepo = context.getbean(icontactrepository.class); list<contacts> results = contactrepo.findbycontactnamelikeandcontactphonelike("%ca%","%090%" , new pagerequest(1, 20));

http://docs.spring.io/spring-data/data-commons/docs/1.6.1.release/reference/html/repositories.html

please have query creation under 1.2.2 defining query methods

java spring oracle jpa spring-data

No comments:

Post a Comment