the call em.find(Department.class, “D1”) returns null even when D1 exists in database.
the debug log shows message as :
Sole candidate for id is com.ge.dsp.iwork.entity.Department and has no subclasses, so returning without checking datastore
What does that mean? why it returns null?
I then tried to use the
departmentId = emp.getDepartment().getDeptNo().trim();
Query query = em.createQuery("SELECT d FROM Department d WHERE
trim(d.deptNo) = :departmentId");
query.setParameter("departmentId", departmentId);
note: the departmentId is already trim before passing to parameter here.
The query printed in the log is as:
SELECT 'com.ge.dsp.iwork.entity.Department' AS
NUCLEUS_TYPE,D.DEPTNAME,D.DEPTNO,D.LOCATION,D.MGRNO FROM DEPARTMENT D WHERE D.DEPTNO =
<'D1'>
and returns 0 rows.
When I modified the query to
departmentId = emp.getDepartment().getDeptNo().trim();
Query query = em.createQuery("SELECT d FROM Department d WHERE trim(d.deptNo) = :departmentId"); // 'D1'");
query.setParameter("departmentId", departmentId.trim());
note: departmentId is now trim again while setting it as parameter.
the log file shows query as:
SELECT 'com.ge.dsp.iwork.entity.Department' AS NUCLEUS_TYPE,D.DEPTNAME,D.DEPTNO,D.LOCATION,D.MGRNO FROM DEPARTMENT D WHERE D.DEPTNO = 'D1'
and returns the entity from DB.
Why is this case? when does datanuclueus add angle brackets <> to the parameter?
Please advice
thanks,
“Not checking datastore” means it knows what is the type of the object to be returned so it is not checking the datastore to validate the type. Why it returns null only you can answer since you know what is in the datastore, what is in the log and what is that class.
Angle brackets symbolise a parameter to a JDBC statement (so in the real statement that is a “?”). This is LOGGING, not what goes to the datastore.