I'm facing with a strange situation when i use named query or native query to filter data using less than '<' or greater than '>' sign. For example i have a catalog of codes and i make a navigation through this codes and for the firs code that is " 000481" the next code is "-PR. 2L"(this is correct) but the previous of the "-PR. 2L" is "PR. 2L" not " 000481" how is correctly.
If i run the query through the Execute Command... the result is correct. If is important i use Mssql 2005 server and for the persistance EclipseLink jpa 2.1
I think the problem is because of - sign that is in the cod "-PR. 2L"
Thanks in advanced!
@SuppressWarnings("unchecked")
public Cods previous(String cod, String codUnit) {
EntityManager em = getEntityManager();
em.setProperty("codUnit", codUnit);
Query query = em.createQuery("SELECT c FROM Cods c WHERE c.cod < :cod ORDER BY c.cod DESC");
query.setParameter("cod", cod);
Cods p = null;
try {
List<Cods> lP = query.setMaxResults(1).getResultList();
if (!lP.isEmpty()) {
p = (Cods) lP.get(0);
}
} finally {
em.close();
}
return p;
}