Code:
package de.datenbanktest.bean;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class Ausführung {
public static void main(String[] args){
/**try{
InitialContext ctx = new InitialContext();
NamingEnumeration<Binding> list = ctx.listBindings("");
while(list.hasMore()){
Binding binding = list.next();
System.out.println(binding.getName() + " : " + binding.getObject());
}
PersonDBManagerRemote remote = (PersonDBManagerRemote) ctx.lookup(PersonDBManagerBean.RemoteJNDIName);
remote.create("Name", "Vorname");
}
catch (NamingException e){
e.printStackTrace();
}*/
try {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
env.put(Context.URL_PKG_PREFIXES, "com.sun.enterprise.naming");
env.put(Context.STATE_FACTORIES, "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
env.put(Context.PROVIDER_URL, "iiop://localhost:3700");
InitialContext ic = new InitialContext(env);
System.out.println(PersonDBManagerBean.class.getName());
PersonDBManagerRemote remoteObject = (PersonDBManagerBean) ic.lookup("Bean");
remoteObject.create("Test","Name");
} catch (NamingException e) {
e.printStackTrace();
}
}
}
Code:
package de.datenbanktest.bean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
@Stateless(mappedName="Bean")
public class PersonDBManagerBean implements PersonDBManagerRemote, PersonDBManagerLocal {
public static final String RemoteJNDIName = PersonDBManagerRemote.class.getSimpleName() + "/remote";
@PersistenceContext(name="person")
EntityManager em;
@Override
public Person create(String nachname, String vorname) {
Person p = new Person();
p.setNachname(nachname);
p.setVorname(vorname);
System.out.println(p.getNachname());
System.out.println(p.getVorname());
em.persist(p);
return p;
}
@Override
public Person getByName(String name) {
Person p = null;
Query q = em.createNamedQuery("Select t from Peron t where nachname=:n");
q.setParameter("n", name);
p = (Person) q.getResultList().get(0);
return p;
}
}
Code:
package de.datenbanktest.bean;
import javax.ejb.Remote;
@Remote
public interface PersonDBManagerRemote {
public abstract Person create(String nachname, String vorname);
public abstract Person getByName(String name);
}
Jetzt zeigt er an:
de.datenbanktest.bean.PersonDBManagerBean
javax.naming.NameNotFoundException: Bean 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 com.sun.enterprise.naming.RemoteSerialContextProviderImpl.lookup(RemoteSerialContextProviderImpl.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:154)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:687)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:227)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1846)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1706)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:1088)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:223)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:806)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:563)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2567)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)
Ich bin echt am verzweifeln. Ich habe das Beispiel aus dem Video2Brain JavaEE benutzt. In den Kapiteln wird weder etwas in jndi.properties eingestellt, noch ein Local Interface erstellt. Selbst das Beispielprogramm der DVD funktioniert nicht. Was kann hier denn noch das Problem sein?
Am liebsten würde ich fluchen um mir wenigstens etwas Frust von der Seele zu schreien.