I have a table with columns like: id, externalId, firstname, lastname, email
My Domain:
class Employee {
int id
String externalId
static mapping = {
table "Employee"
id column: "Id"
externalId column: "externalId"
version false
}
}
My Service:
class EmployeeService {
def getEmployee(externalId) {
def employee = new Employee();
employee.findAllByExternalId("1234");
return employee
}
Error message in logs say:
No signature of method Employee.findAllByExternalId is applicable for argument types (java.lang.String_ values: [1234]
My goal is to load an instance of Employee where the externalId matches what I'm giving it. What am I doing wrong?
Thanks!
You do know there is a lot wrong with all of that
You should be looking up
But that is all very long winded what are you trying to do verify it exists or return a list of all employees that have that id ? You refer it to it as getEmployee so I presume you are trying to find one and yet you are looking for an iteration by doing findAll
are some alternative methods and possible less intense on db depending on what you are trying achieve specifically the boolean vs your current method
Also I called
externalIdd
since when it comes.where
sometimes having same variable names as what is called causes issues hence the alterationE2A As per your comment if you only require id then an id usually is Long hence the strict definition of
Long
you may usedef
- def is more generic and will return anything. I have refined the where to only include property ofid
so if it finds record it will return id then?:0L
if nothing found return 0L
For long so return a zero Long you could replace that with?:null
or not declare it at all.