users@glassfish.java.net

Re: Can't use JPQL for quering Entities with JPA

From: <glassfish_at_javadesktop.org>
Date: Tue, 07 Apr 2009 13:11:38 PDT

Oh yes sorry, I forgot.

I tried two way:
1) NamedQueries:

Here the definition:
@NamedNativeQueries( value = {
                @NamedNativeQuery(
                                name = "byName",
                                query = "SELECT u FROM Users u WHERE u.username = ?1"
                )
})

In in the Code:
Query q = em.createNamedQuery("byName");
q.setParameter("username", name);
List o = q.getResultList();

2) Direct:
Query q = em.createQuery("select u from Users u where u.username = :username");
q.setParameter("username", name);
List o = q.getResultList();

Thanks
[Message sent by forum member 'flyingfinger' (flyingfinger)]

http://forums.java.net/jive/thread.jspa?messageID=341044