Reputation: 33
I've got a class MovieElement, a field url which is the id, and an other field name. Just for testing the values of name and url are the same. An object is persisted with name & url = "www.test.com" But I cannot get the wildcard working, I tried a query like:
query = em.createQuery("SELECT m FROM MovieElement m WHERE m.name LIKE :keyword");
query.setParameter("keyword", "%test%");
query.getResultList();
This gives an empty result.
But the following works:
query = em.createQuery("SELECT m FROM MovieElement m WHERE m.name LIKE :keyword");
query.setParameter("keyword", "www.test.com");
query.getResultList();
Evenso all the next ones results in a null:
MovieElement el = em.find(MovieElement.class, "%test%");
query = em.createQuery("SELECT m FROM MovieElement m WHERE m.name LIKE :keyword");
query.setParameter("keyword", "www.test.co_");
query.getResultList();
query = em.createQuery("SELECT m FROM MovieElement m WHERE m.name LIKE :keyword");
query.setParameter("keyword", "%");
query.getResultList();
Due to the last query it seems the code doesn't take the wildcard into account. Further I'm using DataNucleus and MongoDb.
Anyone an idea? Thx!
Upvotes: 0
Views: 1046
Reputation: 33
Found the solution: Seems like Datanucleus for mongodb recognizes ".*" as the wildcard instead of "%"
Upvotes: 1