Spring Data optional parameter in query method

I don’t believe you’ll be able to do that with the method name approach to query definition. From the documentation (reference): Although getting a query derived from the method name is quite convenient, one might face the situation in which either the method name parser does not support the keyword one wants to use or … Read more

IN-clause in HQL or Java Persistence Query Language

Are you using Hibernate’s Query object, or JPA? For JPA, it should work fine: String jpql = “from A where name in (:names)”; Query q = em.createQuery(jpql); q.setParameter(“names”, l); For Hibernate’s, you’ll need to use the setParameterList: String hql = “from A where name in (:names)”; Query q = s.createQuery(hql); q.setParameterList(“names”, l);

JPQL IN clause: Java-Arrays (or Lists, Sets…)?

I’m not sure for JPA 1.0 but you can pass a Collection in JPA 2.0: String qlString = “select item from Item item where item.name IN :names”; Query q = em.createQuery(qlString, Item.class); List<String> names = Arrays.asList(“foo”, “bar”); q.setParameter(“names”, names); List<Item> actual = q.getResultList(); assertNotNull(actual); assertEquals(2, actual.size()); Tested with EclipseLInk. With Hibernate 3.5.1, you’ll need to … Read more

Adding IN clause List to a JPA Query

When using IN with a collection-valued parameter you don’t need (…): @NamedQuery(name = “EventLog.viewDatesInclude”, query = “SELECT el FROM EventLog el WHERE el.timeMark >= :dateFrom AND ” + “el.timeMark <= :dateTo AND ” + “el.name IN :inclList”)

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)