Created
April 5, 2010 00:08
-
-
Save marcospereira/355836 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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