users@glassfish.java.net

RE: Glassfish does not find deployed class!

From: Martin Gainty <mgainty_at_hotmail.com>
Date: Mon, 25 May 2009 18:13:47 -0400

//my /conf/persistence.xml
<?xml version="1.0" encoding="UTF-8"?>

<!-- Copyright 2006 Sun Microsystems, Inc. All rights reserved.
 You may not modify, use, reproduce, or distribute this software except
 in compliance with the terms of the License at:
 http://developer.sun.com/berkeley_license.html
 $Id: persistence.xml,v 1.2 2007/01/25 20:49:06 yutayoshida Exp $ -->
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">

<!-- this is the unit-name from PersistenceContext -->
  <persistence-unit name="PetCatalogPu" transaction-type="JTA">
    <jta-data-source>jdbc/PETCatalogDB</jta-data-source>
    <properties/>
  </persistence-unit>
</persistence>

/***********public interface CatalogFacade ***********/
package sessionpagination.model;
import java.util.Collection;
import java.util.List;
public interface CatalogFacade {
    public Item getItem(String itemID);
    public Category getCategory(String id);
    public List getCategorys();
    public int getItemCount();
    public List<Item> getItems(int firstItem,int batchSize );
}

/***********public class CatalogFacadeBean ***********/
package sessionpagination.model;
import java.util.Collection;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
//Local is useless for our purposes
//BEAN implements the Facade
@Stateless
public class CatalogFacadeBean implements CatalogFacade {

 //unitName is what JNDI LOOKUP uses to lookup this bean
    @PersistenceContext(unitName="PetCatalogPu")
    private EntityManager em;

    public Item getItem(String itemID)
    {
        Item item = em.find(Item.class,itemID);
        return item;
    }
    public Category getCategory(String id)
   {
        Category category = em.find(Category.class,id);
        return category;
    }
    
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public List<Item> getItems(int firstItem,int batchSize) {
        Query q = em.createQuery("select object(o) from Item as o");
        q.setMaxResults(batchSize);
        q.setFirstResult(firstItem);
        List<Item> items= q.getResultList();
        return items;
    }
    
    @SuppressWarnings("unchecked")
    public List getCategorys() {
        Query q = em.createQuery("select object(o) from Category as o");
        List<Category> categories= q.getResultList();
        return categories;
    }

    public int getItemCount() {
        Query q = em.createQuery("select count(o) from Item as o");
        int count = ((Long)q.getSingleResult()).intValue();
        return count;
    }
}

HTH
Martin Gainty
______________________________________________
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.

> Folks:
>
> I am using Glassfish V2.1.
>
> I am trying to deploy and use an EJB (Version 3). The EJB is part of a complete Enterprise application. It is within a JAR that is deployed with a WAR within an EAR.
>
> The EJB is pretty straightforward. It uses a local interface:
>
> @Local
//no facade?
> public interface CategoriesLocal
> {
//what does this do?
> public int save(Categories nwCategory);
> }
//any accessors for this interface????????????

> and the bean itself is more a skeleton than anything else:
>
> @Stateless
> public class CategoriesFacade implements CategoriesLocal
> {
>
> /**
> * Default constructor.
> */
> public CategoriesFacade() {
> }
>
> @Override
> public int save(Categories nwCategory) {
> return 0;
//?
> }
>
> The client code, at the moment, uses old- style JNDI (because DI is failing for some reason):
>
> try
> {
> InitialContext ctx = new InitialContext();
> CategoriesLocal local = (CategoriesLocal )ctx.lookup("com.path.CategoriesFacade");
> .
> .
> .
>
> Based on documentation of EJB3 and Glassfish, the client code should be able to get an instance of the facade from the server. But when the client code is run, I get the following exception:
>
> WARNING: javax.naming.NameNotFoundException: com.path.CategoriesFacade not found
> at com.sun.enterprise.naming.TransientContext.doLookup(TransientContext.java:216)
> at com.sun.enterprise.naming.TransientContext.lookup(TransientContext.java:188)
> at com.sun.enterprise.naming.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:74)
> at
> <other lines omitted for brevity>
>
> Obviously, I am missing something. Can someone tell me why this is not working???
> [Message sent by forum member 'factor_3' (factor_3)]
>
> http://forums.java.net/jive/thread.jspa?messageID=347582
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>

_________________________________________________________________
Insert movie times and more without leaving Hotmail®.
http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGLM_WL_HM_Tutorial_QuickAdd1_052009