Skip to content

Instantly share code, notes, and snippets.

@marcospereira
Created April 5, 2010 00:08
Show Gist options
  • Save marcospereira/355836 to your computer and use it in GitHub Desktop.
Save marcospereira/355836 to your computer and use it in GitHub Desktop.
package models;
import java.util.List;
import play.db.jpa.JPA;
import play.db.jpa.Model;
import javax.persistence.Query;
import javax.persistence.Table;
import javax.persistence.Entity;
@Entity
@Table(name = "users")
public class User extends Model {
public String username;
public String email;
public String password;
public String toString() {
return username;
}
public static User byUsername(String username) {
Query query = JPA.em().createQuery("from User u where u.username = :username");
query.setMaxResults(1);
query.setParameter("username", username);
List<User> results = query.getResultList();
if (results.isEmpty()) { //
return null;
}
return results.get(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment