2 Replies Latest reply on Jun 23, 2008 2:58 PM by Denis Golovin

    Auto generate database on startup

    Shervin Asgari Master


      I have a Seam / Ejb3 application and I want JBoss to automatically create the database if it is not present on startup.

      Any idea on how to do this?

        • 1. Re: Auto generate database on startup
          Shervin Asgari Master

          I think I found it by using persistence.xml.
          Thanks anyways

          • 2. Re: Auto generate database on startup
            Denis Golovin Master

            This can be done by adding hibernate.hbm2ddl.auto property for persistence-unit in persistence.xml file.
            It enable utomatic validation or export schema DDL to the database when the SessionFactory is created. With create-drop, the database schema will be dropped when the SessionFactory is closed explicitly.
            Available values are: validate | update | create | create-drop


            <persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
             <persistence-unit name="sample">
             <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
             <property name="hibernate.hbm2ddl.auto" value="create-drop"/>