I am having trouble figuring out how to identify duplicates in a table (where lastName and firstName are equal). I will give the working SQL and my attempted JPA.
Working SQL:
Code:
SELECT DISTINCT c1.*
FROM Contact c1
inner join Contact c2 on
c1.firstName = c2.firstName
AND c1.lastName = c2.lastName
AND c1.contactId <> c2.contactId
ORDER BY c1.lastName, c1.firstName
Attempted JPA:
Code:
String query = "select distinct c1 from Contact c1 "
+ " inner join Contact c2 "
+ " where c1.firstName = c2.firstName "
+ " and c1.lastName = c2.lastName "
+ " and c1.contactId <> c2.contactId "
+ " order by c1.lastName, c1.firstName";
I keep getting the following errors when I run the JPA code. Some of the name fields are null, and I don't know how to get "c2" part of the "path" since it is the same table. How does one solve this?
JPS/Hibernate Error Log:
ERROR: Path expected for join!
ERROR: Invalid path: 'c2.firstName'
ERROR: right-hand operand of a binary operator was null
ERROR: <AST>: unexpected end of subtree
ERROR: Invalid path: 'c2.contactId'
ERROR: right-hand operand of a binary operator was null