0 Replies Latest reply on Jul 12, 2005 2:15 PM by Michael Price

    Cannot get Entity Manager using MySQL

    Michael Price Newbie

      I am trying to use JBoss 4.0.3RC1 with MySQL 4.0.24 with Connector/J 3.1.8a and have not been successful so far. I have not been able to find a good source of documentation on this so I have tried to piece it together from multiple sources.

      One must put a mysql-ds.xml file in <JBOSS_HOME>\server\default\deploy. Here is mine.

      <?xml version="1.0" encoding="UTF-8"?>

      <!-- $Id: mysql-ds.xml,v 2004/12/01 11:46:00 schrouf Exp $ -->
      <!-- Datasource config for MySQL using 3.0.9 available from:


      <!-- sql to call when connection is created
      <new-connection-sql>some arbitrary sql</new-connection-sql>
      <!-- sql to call on an existing pooled connection when it is obtained from pool
      <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>

      <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->



      Then in the .ear file inside the .par file inside a folder called META-INF you must have a persistence.xml file. Here is mine.

      <?xml version="1.0" encoding="UTF-8"?>



      I also copied the mysql-connector-java-3.1.8-bin.jar from my Connector/J distribution into <JBOSS_HOME>/server/default/lib directory.

      This is a Session Bean which tries to get an Entity Manager but always gets null;

      package pdb;

      import java.util.*;
      import javax.ejb.*;
      import javax.persistence.*;

      public class FormBean implements FormInterface {
      private String firstName;
      private String lastName;
      private Hashtable<String, String> errors;

      // EntityManagerFactory emf = Persistence.createEntityManagerFactory("person");
      // EntityManager em = emf.createEntityManager();

      protected EntityManager em;

      public boolean validate() throws EMNullException
      boolean allOK=true;
      errors.put("firstName","Please enter your first name");
      errors.put("lastName","Please enter your last name");
      PersonBean person = new PersonBean(firstName, lastName);
      if(em != null)
      em.persist( person );
      throw new EMNullException ();
      return allOK;

      public String getErrorMsg(String s)
      String errorMsg=(String)errors.get(s.trim());
      return (errorMsg == null) ? "":errorMsg;

      public FormBean()
      firstName = "";
      lastName = "";
      errors = new Hashtable<String, String>();

      public String getFirstName()
      return firstName;

      public String getLastName()
      return lastName;

      public void setFirstName( String fname)
      firstName = fname;

      public void setLastName( String lname )
      lastName = lname;


      Any help is greatly appreciated. Also when I deploy my .ear file, this is one of the messages displayed in the server startup window

      13:53:25,750 INFO [JaccHelper] pdb.FormBean has no @SecurityDomain - skipping JACC configuration

      I don't know if it matters.

      Thanks, Mike Price