3 Replies Latest reply on Nov 12, 2009 2:56 AM by jaikiran

    Will EJB delete tables automatically

      I'm new to EJB.

      I have created an EJB application and when I shutdown the server, it drops the tables created by the Entity. When I am back to the application after a restart, the table is back with no data.

        • 1. Re: Will EJB delete tables automatically
          wolfgangknauf

          Hi,

          this is the default behavior, which is declared in "persistence.xml":

          <?xml version="1.0" encoding="UTF-8"?>
           <persistence 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_1_0.xsd"
           version="1.0">
           <persistence-unit name="myPersistenceUnit">
           <jta-data-source>java:/DefaultDS</jta-data-source>
           <properties>
           <property name="hibernate.hbm2ddl.auto" value="create-drop" />
           </properties>
           </persistence-unit>
           </persistence>
          

          See here (last table in the chapter) for other values: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html#configuration-optional

          Best regards

          Wolfgang

          • 2. Re: Will EJB delete tables automatically

            Hi Wolfgang,

            Thanks for your reply. But, I have a doubt. In real-time scenario where user details are stored in a database table, do we let the server drop the tables? Or is there a mechanism where we can restore the data or automatically cache it in the server files?

            • 3. Re: Will EJB delete tables automatically
              jaikiran

               

              "james4u" wrote:
              But, I have a doubt. In real-time scenario where user details are stored in a database table, do we let the server drop the tables? Or is there a mechanism where we can restore the data or automatically cache it in the server files?


              In production environments, the DB is created only once. This setting in the persistence.xml is turned off to avoid any kind of changes to the schema or contents during the entitymanagerfactory creation.