For a MySQL database the NamedQuery did not work.
The annotations:
@Entity
@Table(name="Member")
@NamedQueries({
@NamedQuery(name="Member.loadByEmail", query="select m from Member m where email= :email"),
@NamedQuery(name="Member.loadByEmailAndPassword", query="select m from Member m where email= :email and password= :pwd")
})
@NamedNativeQueries({
@NamedNativeQuery(name="Member.nLoadByEmail", query="select m.* from Member m where email= :email", resultClass=Member.class),
@NamedNativeQuery(name="Member.nLoadByEmailAndPassword", query="select m.* from Member m where email= :email and password= :pwd", resultClass=Member.class)
})
public class Member implements Serializable{...
The code to create the query:
public Object findMemberByEmail(String email){
return em.createNamedQuery("Member.LoadByEmail", Member.class).setParameter("email", email).getSingleResult();
}
public Object nFindMemberByEmail(String email){
return em.createNamedQuery("Member.nLoadByEmail").setParameter("email", email).getSingleResult();
}
No comments:
Post a Comment
Thank you for commenting!