Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Unable to register JNDI Name

 
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);

}

}
----------------------------------------------------------
-------------------------
 
Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic