2 Replies Latest reply on Jan 6, 2012 6:23 AM by je le

    JBoss:EJB is not creating table in MySQL DB

    Gurubg G Newbie

      Hello Folks,

       

      I have a strange problem, I am not receiving any error when I deploy my EJB project to JBoss . I have a single entity bean defined and expecting it to be created in MySQL DB. But strangely I do not see any table created . Has anyone faced the same problem before ?

      I am using Eclipse IDE, MySQL server 51.1 and JBoss 5.0.1 server..

       

      Please find the log attached  ..

       

      And I am posting the configuration files I have used.

       

       

      Peristence.xml

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

      <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

      <persistence-unit name="LessonDS-PU" transaction-type="JTA">

      <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <jta-data-source>java:/lessonds</jta-data-source>

        <exclude-unlisted-classes>false</exclude-unlisted-classes>

          <properties>

            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>

            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>

          </properties>

        </persistence-unit>

      </persistence>

       

       

      mysql-ds.xml

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

       

       

      <!-- $Id: mysql-ds.xml 41017 2006-02-07 14:26:14Z acoliver $ -->

      <!--  Datasource config for MySQL using 3.0.9 available from:

      http://www.mysql.com/downloads/api-jdbc-stable.html

      -->

       

       

      <datasources>

        <local-tx-datasource>

        <jndi-name>lessonds</jndi-name>

        <connection-url>jdbc:mysql://localhost:3306/lessonds</connection-url>

        <driver-class>com.mysql.jdbc.Driver</driver-class>

        <user-name>root</user-name>

        <password>guru</password>

      <!--    <connection-property name="autoReconnect">true</connection-property> -->

             <metadata>

              <type-mapping>mySQL</type-mapping>

              </metadata>

          </local-tx-datasource>

      </datasources>

       

       

      I have placed the DB conenctor file mysql-connector-java-5.1.14-bin.jar in \server\default\lib folder ..

       

      This is my code for Entity which I am trying to create

       

      Entity bean

       

      package com.lessonejb.entities;

       

       

      import java.io.Serializable;

      import java.util.Set;

       

       

      import javax.persistence.CascadeType;

      import javax.persistence.Entity;

      import javax.persistence.GeneratedValue;

      import javax.persistence.Id;

      import javax.persistence.ManyToMany;

      import javax.persistence.Table;

      import javax.persistence.OneToMany;

       

       

      //@SuppressWarnings("serial")

      @Entity

      @Table(name="lessonuser")

       

       

      public class User implements Serializable {

                private static final CascadeType[] ALL = null;

                private String email;

                private String password;

                private String name;

                private String surname;

                private int role;

                private long userID;

                private Set <Course> coursesCreated;

                private Set <Course> coursesEnrolled;

                private Set <Test> testsCreated;

                private Set <Test> testsTaken;

       

       

       

       

                /**

                 * Gets the analysis unique identifier.

                 * This field is used as primary key for persistence.

                 * @return analysis unique identifier

                 */

                @Id

                public String getEmail()

                {

                          return email;

                }

       

                /**

                 * Sets the analysis unique identifier

                 * @param id unique identifier to set

                 */

                public void setEmail(String email)

                {

                          this.email = email;

                }

       

                /** Password */

                public String getPassword()

                {

                          return password;

                }

       

                public void setPassword(String email)

                {

                          this.password = password;

                }

       

                /** Name of the user */

                public String getName()

                {

                          return name;

                }

       

                public void setName(String name)

                {

                          this.name = name;

                }

       

                /** Surname of the user */

                public String getSurname()

                {

                          return surname;

                }

       

                public void setSurname(String surname)

                {

                          this.surname = surname;

                }

       

                /** Role of the user 1-Trainer, 2-Trainee, 3-Assistant*/

                public int getRole()

                {

                          return role;

                }

       

                public void setRole(int role)

                {

                          this.role = role;

                }

       

                /** Role of the user 1-Trainer, 2-Trainee, 3-Assistant*/

                public long getUserID()

                {

                          return userID;

                }

       

                public void setUserID(long userID)

                {

                          this.userID = userID;

                }

      }

       

      But I do not see any table named "lessonuser" created in the "lessonds" database.

      Can someone point out if I am going wrong somewhere ?

       

      Thanks in advance ..

      Guru

        • 1. JBoss:EJB is not creating table in MySQL DB
          Wolfgang Knauf Master

          Hi,

           

          first of all: you use a JPA 2.0 persistence.xml, but JBoss 5.x only supports 1.0. Maybe it is silently ignoring it ;-).

           

          Next step: activate sql logging of the persistence layer. To do so, add this to your persistence.xml:

           

              <properties>

                <property name="hibernate.hbm2ddl.auto" value="create-drop"/>

                <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>

                <property name="hibernate.show_sql" value="true"/>

              </properties>

           

          Maybe there is a  database error message show now.

           

          Hope this helps

           

          Wolfgang

          • 2. Re: JBoss:EJB is not creating table in MySQL DB
            je le Newbie

            hi,  this thread is one year old but I encounter the same problem and get a solution...

             

            I edited persistent.xml file (throw the editor of netbeans) and sudently my tables wouln't update neither create (jboss 4.2.1.GA, jdk 1.5, mysql).

            The guilty line was :

             

              <exclude-unlisted-classes>false</exclude-unlisted-classes>

             

            Setting true or false does nothing, ear deploy, no error message, but no sql neither.

             

            Simply remove this line, now the schema update as suppose to.

             

            A+