aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Rephrase: Does the DOA need to be an session bean as well? SOS.... lossing hairs... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Rephrase: Does the DOA need to be an session bean as well? SOS.... lossing hairs..." Watch "Rephrase: Does the DOA need to be an session bean as well? SOS.... lossing hairs..." New topic
Author

Rephrase: Does the DOA need to be an session bean as well? SOS.... lossing hairs...

Bess Moore
Ranch Hand

Joined: Jun 07, 2003
Posts: 45
Hi there,

I been working in this problem for days, I am a bit confuse, I have created a session bean which contains biz logic and EAO layer,
I understand that we can get the persistence with @PersistenceContext private EntityManager em;

Correct me if I am wrong I am a bit sceptical to use the em in the session bean. (there been lot of arguments stated that we need to ditch )

BUT, still I would want use EntityManager in the EAO layer due to just in case be cause of the mobility of the DAO layer in the future.

So I have implemented DAO design pattern at below but is not working, is giving me:

Unable to get an Entity Manager Instance
javax.naming.NameNotFoundException: No object bound to name java:comp/env/persistence/em

I am so confuse, does the DAO need to be a session bean as well? otherwise, what have it miss??

---------------------------EJB---------------------------------------------------------------------------------------

@Stateless
@Remote
public class CategoryModelImpl implements CategoryModelIF {

public CategoryModelImpl() { }


public Category[] getAllCategorys() throws CigCategoryException {
EAOFactoryManager eaoFactoryMgr = EAOFactoryManager.getEAOFactoryManager(EAOFactoryManager.TOPLINK);
CategoryEAOIF catDAO = eaoFactoryMgr.getCategoryEAOIF();
return catDAO.getAllCategorys();
}

----------DAO---------------------------------------------------------------------------------
import exception.CategoryException;
import bizlogicif.CategoryModelIF;
import java.util.*;
import javax.ejb.*;
import javax.persistence.*;

import persistence.entities.Category;
import javax.naming.*;

public class CategoryEAOImpl implements CategoryEAOIF{

private EntityManager em;

public CategoryEAOImpl(){
em = getEntityManager();
}

private EntityManager getEntityManager() {
try {
InitialContext ctx = new InitialContext();
return (EntityManager) ctx.lookup("java:comp/env/CigCategoryLookup");
} catch (Exception e) {
System.out.println("Unable to get an Entity Manager Instance");
e.printStackTrace();
return null;
}
}

public void deleteCategory(Category cat)throws CategoryException{
String id = cat.getCatId();
cat = em.find(Category.class, id);
if(cat == null) {
throw new CategoryException("Record for " + id + " not found");
} else {
em.remove(cat);
}
}

public Category[] getAllCategorys()throws CategoryException{
Query query = em.createNativeQuery("SELECT cat_id, cat_name, cat_description, version FROM Category", Category.class);
List categories = query.getResultList();
return (Category[])categories.toArray(new Category[0]);
}

}
------------------------------------------------------------------------------------------------------
In web xml
<web-app …>

<ejb-ref>
<ejb-ref-name>CigCategoryLookup</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<remote>cig.bizlogicif.CategoryModelIF</remote>
<ejb-link>CategoryModelImpl</ejb-link>
</ejb-ref>
</web-app>

Welcome to the real world, it sucks, but you're gonna love it !!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Rephrase: Does the DOA need to be an session bean as well? SOS.... lossing hairs...