This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes CriteriaBuilder - I need help converting sql statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "CriteriaBuilder - I need help converting sql statement" Watch "CriteriaBuilder - I need help converting sql statement" New topic
Author

CriteriaBuilder - I need help converting sql statement

Brian Storenson
Ranch Hand

Joined: Aug 24, 2013
Posts: 44
I am trying to understand how CriteriaBuilder works. I am trying to implement a createPerson() that creates a record for a new person. The method below will be used to check and see if there is 1 or more records that have the same first and last name of the person that I want to add to my database. I want to convert the following sql statement into the Criteria API syntax:

SELECT COUNT( * )
FROM Person p
WHERE UPPER(p.FIRST_NAME) = UPPER('type.firstName') AND UPPER(P.LAST_NAME) = UPPER('type.lastName');




Can you help? I have been looking at the Criteria API, and the JEE tutorial on JPA. Now I am stuck.
Brian Storenson
Ranch Hand

Joined: Aug 24, 2013
Posts: 44
This is supposed to be a good tutorial on JPA Criteria API:
http://www.ibm.com/developerworks/java/library/j-typesafejpa/

I will start reading that now.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: CriteriaBuilder - I need help converting sql statement
 
Similar Threads
How to count the number of rows of a JPA 2 CriteriaQuery in a generic JPA DAO?
Can anyone tell why is this query not valid?
code review: JPA criteria
JPA Criteria API and EmbeddedIDs
Searching row in database by a column which is not a primary key