Version 1

    I am trying to create a Entity bean to connect with a MySql databse using remote client but its giving error,using Jboss eap 7.1,Eclipse Juno to connect with Mysql databse 5.6,below are the source codes:


    Entity Class:

    package com.ibytecode.entities;



    import javax.persistence.Entity;

    import javax.persistence.Id;

    import javax.persistence.Column;


    @Entity(name = "project")

    public class Project implements Serializable {

        private static final long serialVersionUID = 1L;


        public Project() {





        private int id;

        private String name;

        private String post;


        @Column(name = "dept_no")

        private int deptNo;


        public int getid() {

            return id;


        public void setid(int id) {

   = id;


        public String getname() {

            return name;


        public void setname(String name) {

   = name;


        public String getpost() {

            return post;


        public void setpost(String post) {

   = post;





        public String toString() {

            return "Project [id=" + id + ", name="

                    + name + ", post="

                    + post + "]";




    Remote Interface:



    import java.util.List;

    import javax.ejb.Remote;


    import com.ibytecode.entities.Project;



    public interface IProject {

        void saveProject(Project project);

        Project findProject(Project project);

        List<Project> retrieveAllProjects();




    Session Bean:

    package com.ibytecode.businesslogic;


    import java.util.List;

    import javax.ejb.Stateless;

    import javax.persistence.EntityManager;

    import javax.persistence.PersistenceContext;

    import javax.persistence.Query;



    import com.ibytecode.entities.Project;



    public class ProjectBean implements IProject {


        @PersistenceContext(unitName = "JPADB")

        private EntityManager entityManager;


        public ProjectBean() {   }



        public void saveProject(Project project) {





        public Project findProject(Project project) {

            Project p = entityManager.find(Project.class,


            return p;




        public List<Project> retrieveAllProjects() {


            String q = "SELECT id from " + Project.class.getName() + " entity";

            Query query = entityManager.createQuery(q);

            List<Project> projects = query.getResultList();

            return projects;






    package com.ibytecode.clientutility;



    import java.util.Properties;

    import javax.naming.Context;

    import javax.naming.InitialContext;

    import javax.naming.NamingException;



    public class JNDILookupClass {


               * location of JBoss JNDI Service provider the client will use. It should be

               * URL string.


              private static final String PROVIDER_URL = "jnp://localhost:1099";




               * specifying the list of package prefixes to use when loading in URL

               * context factories. colon separated


              private static final String JNP_INTERFACES = "org.jboss.naming:org.jnp.interfaces";




               * Factory that creates initial context objects. fully qualified class name.


              private static final String INITIAL_CONTEXT_FACTORY = "org.jnp.interfaces.NamingContextFactory";



              private static Context initialContext;



              public static Context getInitialContext() throws NamingException {

                        if (initialContext == null) {

                                  // Properties extends HashTable

                                  Properties prop = new Properties();

                                  //prop.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);




                                  prop.put("remote.connections", "default");



                                  prop.put("", "localhost");

                                  prop.put("remote.connection.default.port", "4447");





                                  prop.put(Context.URL_PKG_PREFIXES, JNP_INTERFACES);

                                  prop.put(Context.PROVIDER_URL, PROVIDER_URL);

                                  initialContext = new InitialContext(prop);


                        return initialContext;




    Client Class:


    package com.ibytecode.client;



    import java.util.List;

    import java.util.Properties;



    import javax.naming.Context;

    import javax.naming.NamingException;



    import org.jboss.ejb.client.ContextSelector;

    import org.jboss.ejb.client.EJBClientConfiguration;

    import org.jboss.ejb.client.EJBClientContext;

    import org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration;

    import org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector;




    import com.ibytecode.businesslogic.ProjectBean;

    import com.ibytecode.clientutility.JNDILookupClass;

    import com.ibytecode.entities.Project;



    public class EJBApplicationClient {

              private static final String LOOKUP_STRING = "java:jboss/exported/FirstJPAProject1/ProjectBean!";



              public static void main(String[] args) {



                        final EJBClientConfiguration clientConfiguration = new PropertiesBasedEJBClientConfiguration(


                        final ContextSelector<EJBClientContext> contextSelector = new ConfigBasedEJBClientContextSelector(




                        // set the selector for use


                        IProject bean = doLookup();



                        Project p1 = new Project();

                        p1.setname("Banking App");

                        p1.setpost("Town City");



                        Project p2 = new Project();

                        p2.setname("Office Automation");




                        // 3. Call business logic

                        // Saving new Projects





                        // Find a Project


                        Project p3 = bean.findProject(p1);




                        // Retrieve all projects

                        System.out.println("List of Projects:");

                        List<Project> projects = bean.retrieveAllProjects();

                        for (Project project : projects)





              private static Properties createClientConfigurationProperties() {

                        final Properties properties = new Properties();


                        properties.put("remote.connections", "default");




                        //properties.put("remote.lookupclass", "IProject");

                        // properties.put("","JBOSS-LOCAL-USER");

                        // properties.put("",

                        // "false");



                        return properties;




              private static IProject doLookup() {

                        Context context = null;

                        IProject bean = null;

                        try {

                                  // 1. Obtaining Context

                                  context = JNDILookupClass.getInitialContext();


                                  String lookupName = getLookupName();

                                  // 2. Lookup and cast

                                  bean = (IProject) context.lookup(lookupName);



                        } catch (NamingException e) {



                        return bean;





              private static String getLookupName() {


                         * The app name is the EAR name of the deployed EJB without .ear suffix.

                         * Since we haven't deployed the application as a .ear, the app name for

                         * us will be an empty string


                        String appName = "";



                        // The module name is the JAR name of the deployed EJB without the .jar

                        // suffix.

                        String moduleName = "FirstJPAProject1";




                         * AS7 allows each deployment to have an (optional) distinct name. This

                         * can be an empty string if distinct name is not specified.


                        String distinctName = "";



                        // The EJB bean implementation class name

                        String beanName = ProjectBean.class.getSimpleName();



                        // Fully qualified remote interface name

                        final String interfaceName = IProject.class.getName();



                        // Create a look up string name

                        String name = "ejb:" + appName + "/" + moduleName + "/" + distinctName

                                            + "/" + beanName + "!" + interfaceName;



                        return name;





    And the error i am getting is:


    Aug 22, 2013 10:39:06 AM org.xnio.Xnio <clinit>

    INFO: XNIO Version 3.0.3.GA

    Aug 22, 2013 10:39:06 AM org.xnio.nio.NioXnio <clinit>

    INFO: XNIO NIO Implementation Version 3.0.3.GA

    Aug 22, 2013 10:39:06 AM org.jboss.remoting3.EndpointImpl <clinit>

    INFO: JBoss Remoting version 3.2.3.GA

    Aug 22, 2013 10:39:06 AM org.jboss.ejb.client.remoting.VersionReceiver handleMessage

    INFO: Received server version 1 and marshalling strategies [river]

    Aug 22, 2013 10:39:06 AM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate

    INFO: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@84a74, receiver=Remoting connection EJB receiver [connection=Remoting connection <1a88328>,channel=jboss.ejb,nodename=inp-cc122858-2]} on channel Channel ID e600faf2 (outbound) of Remoting connection 0175650e to localhost/

    Aug 22, 2013 10:39:06 AM org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver handleMessage

    WARN: Unsupported message received with header 0xffffffff

    javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

              at javax.naming.spi.NamingManager.getInitialContext(

              at javax.naming.InitialContext.getDefaultInitCtx(

              at javax.naming.InitialContext.getURLOrDefaultInitCtx(

              at javax.naming.InitialContext.lookup(

              at com.ibytecode.client.EJBApplicationClient.doLookup(

              at com.ibytecode.client.EJBApplicationClient.main(

    Exception in thread "main" java.lang.NullPointerException

              at com.ibytecode.client.EJBApplicationClient.main(