[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Re: no persistent classes found for query class
igor007
do-not-reply at jboss.com
Wed May 6 22:53:05 EDT 2009
i did it as you said but nothing hasd been changed.Could you please tell me how to use jpa in jboss.some excamples.as you said i am using jpa.
import javax.naming.InitialContext;
| import javax.persistence.EntityManager;
| import javax.persistence.EntityManagerFactory;
| import javax.persistence.NoResultException;
| import javax.persistence.Persistence;
| import javax.persistence.Query;
|
| import org.hibernate.Session;
| import org.hibernate.SessionFactory;
|
|
| public class LoginBean {
| private String LoginName;
| private String password;
|
| public String getLoginName() {
| return LoginName;
| }
| public void setLoginName(String loginName) {
| LoginName = loginName;
| }
| public String getPassword() {
| return password;
| }
| public void setPassword(String password) {
| this.password = password;
| }
| public String login() throws Exception{
|
|
| EntityManager em = Contexts.getEntityManager();
|
| Query query = em.createQuery(
| "from User user");
|
|
|
|
|
| // execute query
| try {
| User user = (User)query.getSingleResult();
| // store found user to session
| Contexts.getSession().setAttribute("user", user);
| } catch (NoResultException e) {
| // no user found - return failure
| e.printStackTrace();
| return "failure";
| }
|
| //return success
| return "success";
| }
| }
|
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4229229#4229229
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4229229
More information about the jboss-user
mailing list