File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Unable to register JNDI Name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Unable to register JNDI Name" Watch "Unable to register JNDI Name" New topic
Author

Unable to register JNDI Name

Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 845
I am deploying 2 stateless session bean's under 1 jar.

Under EJB Module's, i am able to see both Stateless Session Bean's.

However when i see under JNDI tree, only 1 bean has it's mappedName. I am not able to make out why the other bean doesn't has mappedName getting registered under JNDI tree.

CarCreatorBean.java(for this class i am able to see it's JNDI name in GlassFish)

----------------------------------
package Pack;

import java.util.List;

import javax.ejb.Stateful;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.FlushModeType;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceUnit;
import javax.persistence.Query;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.EntityResult;

import Factory.CarEAO;
import Factory.EAOFactory;
import Factory.JPAEAOFactory;
/**
* Session Bean implementation class CarCreatorBean
*/
@Stateless(name="StatelessSessionBean", mappedName="ejb/SimpleJNDIName")
@SqlResultSetMapping(name = "CarResults",
entities = @EntityResult(entityClass = Pack.Car.class))

public class CarCreatorBean implements CarCreator {

/**
* Default constructor.
*/
public CarCreatorBean() {
// TODO Auto-generated constructor stub
}

@PersistenceContext(unitName ="actionBazaar")
private EntityManager entityManager;

public void addCarComponents(String horn, String steering, String wheel){
Car car = new Car("horn", "steering", "wheel");
System.out.println("Inside addCarComponents" + entityManager);
entityManager.persist(car);
entityManager.setFlushMode(FlushModeType.COMMIT);
}
public void addMergeCarComponents(String horn, String steering, String wheel){
Car car = new Car("horn", "steering", "wheel");
entityManager.merge(car);
}
public void undoCarComponents(String horn, String steering, String wheel){
Car car = new Car("horn", "steering", "wheel");
entityManager.refresh(entityManager.merge(car));
}
public void deleteCarComponents(Long id){
entityManager.remove(entityManager.find(Car.class, id));
}
public Car retrieveItem(Long id){
Car car = entityManager.find(Car.class, id);
return car;
}
public List sqlQuery(){
// System.out.println("Inside the sqlQuery method");
// Query query = entityManager.createQuery("select c from Car c");

Query query = entityManager.createNamedQuery("findCar");
query.setParameter("steering", "steering");
return query.getResultList();
}

public List sqlQuery1(){
Query query = entityManager.createNamedQuery("findCar1");
query.setParameter(1, "horn");
// set the maximum no. of objects to be retrieved.
query.setMaxResults(4);
// set the initial position for the first result being retrieved.
query.setFirstResult(2);
return query.getResultList();
}

public List nativeResult(){
Query query = entityManager.createNativeQuery("select * from Car");
return query.getResultList();
}

public void carFactory(String steering, String horn, String wheel){
CarEAO carEAO = EAOFactory.jpa.getCarEAO();
carEAO.addCar(steering, horn, wheel);
}

}
-----------------------------------------

CarEAOImpl.java(for this class unable to see it's mappedName in JNDI tree, why?)

-----------------------------------------
package Factory;

import javax.ejb.Stateless;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceUnit;
import javax.sql.DataSource;

import Pack.Car;

@Stateless(name="StatelessSessionBean1", mappedName="ejb/SimpleJNDIName1")
public class CarEAOImpl implements CarEAO{



public CarEAOImpl(){
}

//@PersistenceContext(unitName ="actionBazaar")
// private EntityManager entityManager;

@PersistenceUnit
private EntityManagerFactory emf;

//private EntityManager getEntityManager() throws NamingException{
// return entityManager;
//}
public void addCar(String steering, String horn, String wheel) {
//EntityManager em;

//entityManager = getEntityManager();
EntityManager entityManager = emf.createEntityManager();
System.out.println("getEntityManager() =" + entityManager);
Car c = new Car(steering, horn, wheel);
entityManager.persist(c);

}

}
----------------------------------------------------------
-------------------------


SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to register JNDI Name