[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Re: EntityManager throws a nullpointerexception JBOSS 4.2.2G
July Pyrra
do-not-reply at jboss.com
Tue May 27 04:17:09 EDT 2008
Thank you! It seems to work now! At least I don't get the NullPointerException anymore so the injection worked.
To close the subject, here is my code with the lookup
| package ws.process;
|
| import bd.query.Query;
| import datamodel.DAO.SystemUser;
|
| public class Authentication {
|
| public void authenticate(){
| Context context = new InitialContext();
| QueryInt bean = (QueryInt) context.lookup("Query/local");
| SystemUser _SystemUser = bean.AuthenticateUser("julie","1234");
|
| System.out.println(SystemUser.getId());
| }
| }
|
| package bd.query;
|
| import java.util.List;
| import datamodel.DAO.SystemUser;
|
| import javax.ejb.Stateless;
| import javax.persistence.EntityManager;
| import javax.persistence.PersistenceContext;
|
| @Stateless
| public class Query implements QueryInt{
|
| @PersistenceContext
| EntityManager em;
|
| public SystemUser AuthenticateUser(String uid, String pwd){
| SystemUser _SystemUser = (SystemUser) em.createQuery("select a.systemUser from Account ").getSingleResult();
| return _SystemUser;
|
| }
| }
|
| package bd.query;
|
| import datamodel.DAO.SystemUser;
| import javax.ejb.Local;
|
| @Local
| public interface QueryInt {
| public abstract SystemUser AuthenticateUser(String uid, String pwd);
| }
|
and a very simple persistence.xml
| <?xml version="1.0" encoding="UTF-8"?>
| <persistence>
|
| <persistence-unit name="Nuadu">
| <provider>org.hibernate.ejb.HibernatePersistence</provider>
| <jta-data-source>java:/cuoreds</jta-data-source>
| </persistence-unit>
|
| </persistence>
|
Thanks again!
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4153492#4153492
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4153492
More information about the jboss-user
mailing list