users@glassfish.java.net

Re: Glassfish security - user session linked with database

From: <glassfish_at_javadesktop.org>
Date: Thu, 23 Sep 2010 08:22:19 PDT

> myEntity = em.find(User.class, *id*)
>
> Is there an equivilalent function to find an object
> without using the id property, but another attribute,
> like say the login, and then get the id from this...?

Sure, you can do a standard JPQL query.

Query q = em.createQuery("SELECT object(o) FROM EntityType WHERE o.username = theusername");
myEntity = (EntityType) q.getSingleResult();

Though this is very basic, you probably want to parameterize the query, etc.
[Message sent by forum member 'calhoun']

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