Hi
I've changed my BidClient.class by adding the InitialContext code early in the class
(see below) but it is giving me this error (server side is deploying OK no errors and
BIDDER table created) :
Console:
| Exception in thread "main" javax.naming.NoInitialContextException: Cannot
instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is
java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
| at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
| at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
| at javax.naming.InitialContext.init(InitialContext.java:223)
| at javax.naming.InitialContext.<init>(InitialContext.java:197)
| at Main.main(Main.java:54)
| Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
| at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
| at java.security.AccessController.doPrivileged(Native Method)
| at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
| at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
| at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
| at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
| at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
| at java.lang.Class.forName0(Native Method)
| at java.lang.Class.forName(Class.java:242)
| at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
| at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
| ... 4 more
|
This is my revised BidClient.class (I run it as a Java Application in Eclipse) with the
InitialContext code on top:
JPA Client Coding:
|
|
| import javax.persistence.EntityManager;
| import javax.persistence.EntityManagerFactory;
| import javax.persistence.Persistence;
| import javax.persistence.PersistenceContext;
|
| import org.apache.log4j.Level;
| import org.apache.log4j.Logger;
| import org.apache.log4j.ConsoleAppender;
| import org.apache.log4j.SimpleLayout;
|
| import my.com.eperolehan.entities.Bidder;
|
| import javax.rmi.*;
| import javax.naming.InitialContext;
| import javax.naming.NamingException;
|
| import java.util.*;
|
|
|
| public class Main {
|
|
| private static EntityManagerFactory f;
|
| @PersistenceContext(unitName="BiddingTest")
| private static EntityManager em;
|
|
| public static void main(String[] args) throws NamingException {
|
|
| Logger log = Logger.getLogger(Main.class);
| log.setLevel(Level.WARN);
|
| SimpleLayout layout = new SimpleLayout();
| ConsoleAppender appender = new ConsoleAppender(layout);
|
|
| log.addAppender(appender);
|
|
| try {
|
|
| Properties p = new Properties();
|
| p.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
| p.put("java.naming.provider.url", "localhost:1099");
|
|
| InitialContext ctx = new InitialContext( p );
|
| Object obj = ctx.lookup("/Bidder");
| Bidder bidder = (Bidder) PortableRemoteObject.narrow(obj,Bidder.class);
|
|
| System.out.println("[BidClient] : creating
EntityManagerFactory...");
| log.debug("[BidClient] : creating EntityManagerFactory...");
| f = Persistence.createEntityManagerFactory("BiddingTest");
| System.out.println("[BidClient] : Created.");
| log.debug("[BidClient] : Created.");
| System.out.println("[BidClient] : creating EntityManager...");
| em = f.createEntityManager();
| System.out.println("[BidClient] : Created.");
| log.debug("[BidClient] : Created.");
|
|
| em.getTransaction().begin();
|
|
| try {
| System.out.println("[BidClient] : creating a Bidder...");
| //Bidder bidder = new Bidder();
|
| bidder.setBidderName("Bidder No 1");
| bidder.setBidSessionId(1);
|
|
| em.persist(bidder);
| em.getTransaction().commit();
| System.out.println("[BidClient] : Bidder created and
commited.");
| log.debug("[BidClient] : Bidder created and commited.");
|
| } catch (Exception ex) {
| em.getTransaction().rollback();
| }
|
| System.out.println("[BidClient] : Bidder person created and persisted
successfully.");
| log.debug("[BidClient] : Bidder person created and persisted
successfully.");
|
| } catch (RuntimeException e) {
|
| e.printStackTrace();
|
| } finally {
|
|
|
| }
|
|
| System.out.println("[BidClient] : closing entity manager and
factory...");
| log.debug("[BidClient] : closing entity manager and factory...");
| em.close();
| //f.close();
| System.out.println("[BidClient] : Closed.");
| log.debug("[BidClient] : Closed.");
|
| }
|
|
| }
|
What's wrong?
Many thanks in advance!
Ezani
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4198534#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...